Archive

Archive for April, 2010

GD Library Error: imagecreatetruecolor does not exist (FIX)

April 28, 2010 2 comments
I got the Timthumb php script image resizer installed this morning on my windows (IIS) machine, with about an hour of fiddling, here’s what I went through

1. At the start, all php pages were throwing up a php_via_fastcgi error

Reading some blog posts, the diagnostic step was to do this
%WINDIR%system32inetsrvappcmd.exe list config /section:handlers
/text:* | findstr /i PHP
and I got this result;
path:"*.php"
scriptProcessor:"C:Program Files (x86)phpphp-cgi.exe"

Funnily enough that php-cgi.exe file was missing, even though I appeared to have a partial installation of php on my pc.
So I downloaded the manual installer from PHP, and unzipped the files ontop of my php directory.

Now PHP was working

2. After installing timthumb, I saw that no images were appearing, and navigating directly to the PHP script gave this error

GD Library Error: imagecreatetruecolor does not exist – please contact your webhost and ask them to install the GD library
TimThumb version : VERSION

So, the trick was to open PHP.INI with notepad *IN ADMINISTRATOR MODE*

and add the lines
[PHP_GD2]
extension=php_gd2.dll

IISReset, then it worked!

Categories: Uncategorized

Use IIS under VS 2008, rather than the development server, Casini

April 28, 2010 Leave a comment
If you want to use IIS rather than the development server casini – which starts all projects on some high port, i.e. localhost:54324,

Set up a new application in IIS, point it to the root of your project, and check that it works, by going to a browser, and type localhost/myApp

Then right click your web applicaiton in Visual Studio, select "Property Pages", then "Start Option", set Start URL to localhost/myApp,
check "Use custom webserver", then base URL to "http://localhost/SellSwapBuy".

When you run your app now, you can still debug, but it will be under IIS not Casini.

Categories: Uncategorized

As String, ToString and (string)

April 22, 2010 Leave a comment
Three ways to cast an object to a string .ToString(), as String, and (string), what’s the difference?

((object)1).ToString()  equals "1"
((object)1) as string  equals null
(string)((object)1) throws an exception

Basically, "ToString()" calls a method on "object" or in the closest derived class that overrides the ToString() method.

"As string" performs a cast, but returns null rather than an exception is the cast is not implicitly possible.

(string) peroforms the same cast, but throws an exception on failure.

Categories: Uncategorized

Hash codes for Realex payment processing

April 21, 2010 Leave a comment
Might be of interest to anybody using the Realex payment system in ASP.NET / C#, this is the code to generate MD5 checksums for it:

 // Create an md5 sum string of this string
        static public string GetMd5Sum(string str)
        {
            // First we need to convert the string into bytes, which
            // means using a text encoder.
            Encoder enc = System.Text.Encoding.ASCII.GetEncoder();
            // Create a buffer large enough to hold the string
            byte[] unicodeText = new byte[str.Length];
            enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
            // Now that we have a byte array we can ask the CSP to hash it
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] result = md5.ComputeHash(unicodeText);
            // Build the final string by converting each byte
            // into hex and appending it to a StringBuilder
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < result.Length; i++)
            {
                sb.Append(result[i].ToString("X2"));
            }
            // And return it
            return sb.ToString().ToLower();
        }

Categories: Uncategorized

XmlSerializer Cache

April 21, 2010 Leave a comment
Some benchmarks that shows the overhead of the XMLSerializerCache

var xs = new XmlSerializer(typeof(DataSet));

On a first call, this generates a cached serialization assembly. On my PC, this takes 0.2 seconds. However, on subsequent calls,
this line executes in 0.00006959 seconds.

This is how I timed this;

        private TimeSpan CreateXMLSerializer(int numberOf)
        {
            var dtStart = DateTime.Now;
            var lNumber = Enumerable.Range(1, numberOf);
            foreach (var intIteration in lNumber)
            {
                var xs = new XmlSerializer(typeof(DataSet));
            }
            var dtEnd = DateTime.Now;
            return dtEnd – dtStart;
        }

Categories: Uncategorized

UGFzc3dvcmQ6

April 12, 2010 Leave a comment
What does UGFzc3dvcmQ6 mean?, it’s the Base 64 encoded version of the work Password: and the most ridiculous security feature that
I’ve ever seen in my life.

But where is this used?, on a student project?, nope, it forms the bases of SMTP email authentication.

  AUTH    {blank}    334 UGFzc3dvcmQ6    18    45    noreply@a.com

 AUTH    c3R1cGlk    235 Authenticated    19    18    noreply@a.com

and the password is base 64 encoded too.

Terrible.

Categories: Uncategorized

Mathematically determining your max cpc for adwords

April 5, 2010 Leave a comment
When advertising on Google Adwords, it is essential to get the maths right, or you can end up loosing money on it very quickly.

I’m no expert, but this is what I’ve come up with:
1) bid on several hundred keywords at 0.03p each, and let google cancel the ones that are over competitive. This normally creates a spike and a rapid tail
off of visitors, so the success of this plan can only be seen after a few days.
I found that this bottom-feeding approach brings in cheap traffic, but not much of it.

2) Pay the maximum you can afford to bring in as many visitors as possible, whilst making sure the cost per conversion does not exceed nor equal your average profit per conversion.

Google is unusual in the sense of the more visitors you purchase, the higher the cost per visitor gets. Economies of scale are somewhat reversed in this situation. However, if you make £1 a conversion, and it costs 50p per conversion for 1,000 visitors, or 40p a conversion for 100 visitors, then you are still better paying £500 for £1000 profit than £40 for £100 profit.

To calculate your maximim CPA (Cost per Action), then it is take a specific period, i.e. January 2010, say P is your gross profit in January 2010, C is your cost of sales, N is the number of conversions in Jan ’10. Then your Maximum CPA is (P-C)/N

Now, not every click on an ad will result in a conversion, depending on the ticket value of your product, this could be anything from 1% to 50%. Check your conversion rate bettween your visitors (V) and conversions (N) , then divide this into your  Max CPA i.e. CPA x N/V to get your Max CPC.

Interestingly, combining both equations nullifies your conversion rate: (P-C)/V – But you’ll still need to have your Max CPA to hand to ensure that no individual keyword exceeds your MAX CPA.

Categories: Uncategorized