6th Mar, 2009

Its been quite a while

It’s been quite a while since I last posted. Here is a funny image of a cake fail:

The Long Term Starts Tomorrow

There’s a general sense that automated testing is something you do that costs you time in the short term for a long term benefit. This is probably true to some extent, although I’d argue that if you are really seeing a short term time loss from TDD, then you probably could improve your practice some.

The larger point is that referring to “the long term” makes the benefits seem like something that will happen in the comfortably remote future, along with flying cars and space elevators. Usually, though, the long term starts the first time somebody asks you to add a feature or fix  a bug. Which means next
week. Or tomorrow. Or later today. The benefits accrue faster than you think.

Retrofitting for Tests Never Quite Works

There aren’t a whole lot of programming tasks in the agile world that are as as annoying and frustrating as adding unit tests to existing code. The existing code never has all the structure and hooks needed for good testing, which means refactoring is needed to get any useful testing in. Of course, the
existing code doesn’t, by definition, have tests, so there’s danger involved. Inevitably, there’s some monstrously hairy corner of the code that nobody wants to touch and it just hangs there, untested. You’ll almost always also see that design decisions that were not made with testing in mind are not
particularly amenable to allowing unit testing later on. The cost of retrofitting accrues faster than you think, as well.

Refactoring is Just As Important

The test-driven development process is a three step process. Test, code, refactor. The refactor step gets left off sometimes, but it’s just as important as the other two in getting the full benefit of TDD. There is an
analogy to continuous integration, where the idea is by integrating in more frequent, smaller chunks, the overall integration costs go way down. Similarly, by doing frequent, small refactoring, overall cost of refactoring to keep the code clean goes way down. It helps tremendously to do the refactoring in the tight loop, when you are most familiar with the code and the tests you’ve just written.

4th Oct, 2008

Static and Dynamic Urls

What is a static URL?
A static URL is one that does not change, so it typically does not contain any url parameters. It can look like this: http://www.example.com/archive/january.htm. You can search for static URLs on Google by typing filetype:htm in the search field. Updating these kinds of pages can be time consuming, especially if the amount of information grows quickly, since every single page has to be hard-coded. This is why webmasters who deal with large, frequently updated sites like online shops, forum communities, blogs or content management systems may use dynamic URLs.

What is a dynamic URL?
If the content of a site is stored in a database and pulled for display on pages on demand, dynamic URLs maybe used. In that case the site serves basically as a template for the content. Usually, a dynamic URL would look something like this: http://code.google.com/p/google-checkout-php-sample-code/issues/detail?id=31. You can spot dynamic URLs by looking for characters like: ? = &. Dynamic URLs have the disadvantage that different URLs can have the same content. So different users might link to URLs with different parameters which have the same content. That’s one reason why webmasters sometimes want to rewrite their URLs to static ones.

Hackers sometimes add strange, off-topic hidden content and links to questionable pages. If it’s hidden, you might not even notice it right away; but nonetheless, it can be a big problem. While the Message Center may be able to give you a warning about some kinds of hidden text, it’s best if you also keep an eye out yourself. Google Webmaster Tools can show you keywords from your pages in the “What Googlebot sees” section, so you can often spot a hack there. If you see totally irrelevant keywords, it would be a good idea to investigate what’s going on. You might also try setting up Google Alerts or doing queries such as [site:example.com spammy words], where “spammy words” might be words like porn, viagra, tramadol, sex or other words that your site wouldn’t normally show. If you find that your site actually was hacked, I’d recommend going through our blog post about things to do after being hacked.

There are a lot of issues that can be recognized with Webmaster Tools; these are just some of the more common ones that we’ve seen lately. Because it can be really difficult to recognize some of these problems, it’s a great idea to check your Webmaster Tools account to make sure that you catch any issues before they become real problems. If you spot something that you absolutely can’t pin down, why not post in the discussion group and ask the experts there for help?

Have you checked your site lately?

4th Oct, 2008

Tips from Google

Running a website can be complicated—so we’ve provided Google Webmaster Tools to help webmasters to recognize potential issues before they become real problems. Some of the issues that you can spot there are relatively small (such as having duplicate titles and descriptions), other issues can be bigger (such as your website not being reachable). While Google Webmaster Tools can’t tell you exactly what you need to change, it can help you to recognize that there could be a problem that needs to be addressed.

Google Adsense

It is recommended by Microsoft for dealing with dynamic program code to use the code-behind model, which places this code in a separate file or in a specially designated script tag. Code-behind files typically have names like MyPage.aspx.cs or MyPage.aspx.vb based on the ASPX file name (this practice is automatic in Microsoft Visual Studio and other IDEs). When using this style of programming, the developer writes code to respond to different events, like the page being loaded, or a control being clicked, rather than a procedural walk through the document.

ASP.NET’s code-behind model marks a departure from Classic ASP in that it encourages developers to build applications with separation of presentation and content in mind. In theory, this would allow a web designer, for example, to focus on the design markup with less potential for disturbing the programming code that drives it. This is similar to the separation of the controller from the view in model-view-controller frameworks.

Owen pointed me to a snippet that fixes wordpress permalinks on IIS. Although the solution is not very clean, it works very well. What you need to do is set a 404 error page from your website control panel and point it to a *.php file with the following code.

<?php
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ‘:80′)+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include(’index.php’);
?>

When a user visits a permalink url, IIS will throw a 404 exception which will be handled by the above code. The logic is dead simple: The REQUEST_URL and PATH_INFO servervariables are overridden by the permalink path. In this case it is : /2008/04/30/permalinks-on-iis-wordpress/.

The last line simply loads index.php and opens the correct page because PATH_INFO and REQUEST_URL are correctly set.

The other day I was checking my hotmail account to curiously check how many spam emails have made it to my inbox. To my surprise I found out a “hidden feature” on hotmail to forward mail to another email account. This is what I needed. Well I wouldn’t have to bother checking this account again. After all, I’m having trouble remembering the password and it would take some brain cell crunching to figure that out. Anyways, if you’re interested (probably you’re not), the feature is under options -> “forward mail to another account”.

A light bulb switched on in my head! I was thinking about forwarding mail to my gmail account however I got a little nice error message saying: You’re only able to forward mail to a custom domain or an e-mail address that ends in hotmail.com, msn.com, or live.com. Please try again. This sort of message simply implies that Microsoft is more than aware that their competitors offer a better service.. Why not try and beat them? Ok, so after reading the message I thought why not forward the hotmail account to a custom domain which in turn redirects to gmail anyway? I was so wrong! When I typed in my email @ custom domain I got the same error message again. “Microsoft”, I’m honestly dumbfounded! Why would you want to tell me that your competition is better and then offer me a service that doesn’t work? For god’s sake, why would I want to forward mail to another hotmail, msn or live account? Apparently this is the only forwarding that works.

Screenshot below.

It’s been quite a while since I last posted on here. Anyway, here is a class that encrypts data and encodes it using base64 for use in querystrings. The decrypt function does the opposite thing.. it first decodes and then decryptes the string.

public class Encryption64
{
private byte[] key = {};
private byte[] IV = {18, 52, 86, 120, 144, 171, 205, 239};

public string Decrypt(string stringToDecrypt, string sEncryptionKey)
{
byte[] inputByteArray = new byte[stringToDecrypt.Length + 1];
try {
key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception e) {
return e.Message;
}
}

public string Encrypt(string stringToEncrypt, string sEncryptionKey)
{
try {
key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception e) {
return e.Message;
}
}
}

This is a followup post to a previous post on which I have explained that I bought 2 usb pendrives of 8gb each from ebay which simply didn’t work. I have now discovered that these products were scam. The pendrives were actually 2Gb in size and were manipulated by software to make them look as if they were 8Gb. This explains why files were copied fast after the 2Gb memory was full. Do not ever buy stuff off ebay from Far East sellers cos  most of them are fraudulent sellers. The following image shows how windows sees the pendrive as 8gb.  After formatting the pendrive using Iformat, the size drops down to 2Gb.

This is the reply I got from the seller. It is funny - The seller is claiming that unconfirmed files (whatever they are) have attacked the device (possibly by aliens)! WOW.. that’s trustworthy!

Dear Sir/Madam,

Sorry to hear that. Please try to make sure that the files format is formal.

Note: sometimes some unconfirmed files will attack the device,
it may even the the memo corrupted. so please be care of this problem.

Regards,
Digittrend.

fakeusb.gif



Marcus Evans

Categories