A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

wrt610n “port overlap occurred” – working around and fixing it

There is a very nasty bug in “Linksys by Cisco” WRT610N wireless-N router. When you try to set up port forwarding from two different external ports to two ports with the same number but on different intranet machines, you get a nasty javascript popup error message “Port overlap occurred! Please change your entry!”. This prevents system administrators from setting up a perfectly valid scenario (for example mapping several IP web cams on intranet to different extranet ports).

Luckily the check is done only in javascript and you can still force settings on router bypassing this check.

If you fire up Fiddler dubugging proxy or a similar HTTP sniffer you would be able to see that upon submit the following post request is sent to the router:















Take a look at bolded stuff. It has the port mapping information. I’ve deliberately set wrong port numbers (81, 82…) to bypass the javascript check. I then changed the port numbers to 80 and manually sent the request to the router. It doesn’t distinguish between GET and POST requests so you can just take the modified string and append it to the URL.

Worked for me like a charm!

MySQL Error: Data truncated for column ‘…’ at row 0

If you’ve recently migrated from MySQL 4 to MySQL 5, queries that used to work might cause errors. The thing is that MySQL got much more struct about what data can go where. MySQL 4 used to cast NULL values to 0 INT, DOUBLE, FLOAT etc implicitly. MySQL 5 doesn’t do it so you ether need to make the column you are trying to assign to NULLable or make sure that it is never assigned NULL value.

Default namespace for LINQ to XML query

Linq rocks completely, however when you write queries against XML documents that have namespaces (and most likely the document will only have one namespace) you have to specify them in your queries. Here’s a nice solution from mike a moogly.me.uk – just strip all of the useless namespaces from XDocument object and query away!

public void RemoveNamespace(XDocument xdoc)


foreach (XElement e in xdoc.Root.DescendantsAndSelf())


if (e.Name.Namespace != XNamespace.None)


e.Name = XNamespace.None.GetName(e.Name.LocalName);


if (e.Attributes().Where(a => a.IsNamespaceDeclaration || a.Name.Namespace != XNamespace.None).Any())


e.ReplaceAttributes(e.Attributes().Select(a => a.IsNamespaceDeclaration ? null : a.Name.Namespace != XNamespace.None ? new XAttribute(XNamespace.None.GetName(a.Name.LocalName), a.Value) : a));





If you get PHP error something like “syntax error, unexpected ‘)’, expecting T_PAAMAYIM_NEKUDOTAYIM” it should be immediately obvious to you that PHP parser believes that you are missing a dollar sign in front of one of the variable names on that particular line (for example in isset or foreach clause)

Isn’t this obvious?

Download and install wordpress with single PHP script

One of the common tasts that I have to do recently is installing wordpress on new website. While configuring the WordPress is simple and fast before you get there you need to download wordpress ZIP file, extract it to the correct folder (by default unzipping the file will create folder “wordpress” that you most likely don’t need). I’ve put together the folling script that would automatically download latest WordPress version, unzip it to correct folder and redirect you to configuration page. All you need to do is craete and configure the database.

You can download the script from here. Here’s the script listing for information purposes (because WordPress changes quotation symbols copy-pasting it will not product working PHP code):


$URL = “http://wordpress.org/latest.zip”;

$ch = curl_init($URL);

curl_setopt($ch, CURLOPT_VERBOSE, 1);


curl_setopt ($ch, CURLOPT_URL, $URL);

curl_setopt ($ch, CURLOPT_TIMEOUT, 600);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

$content = curl_exec($ch);

$fh = fopen(“wordpress.zip”, “wb”);

fwrite($fh, $content);


$zip = zip_open(“wordpress.zip”);

$dst_path = $_REQUEST[‘path’];

if ($dst_path == ”) { $dst_path = ‘.’; }

while ($entry = zip_read($zip))


$name = zip_entry_name($entry);

if (preg_match(‘/\/$/’, $name)) { continue; }

$new_name = preg_replace(‘/^wordpress/i’, $dst_path, $name);

if (preg_match(‘/^(.+)\/([^\/]+)$/i’, $new_name, $matches)) {

$directory = $matches[1];

if ($directory != ” && !is_dir($directory)) {

if (!mkdir($directory, 0777, 1)) {

return FALSE;




$fh = fopen($new_name, “wb”);

zip_entry_open($zip, $entry, “rb”);

while ($data = zip_entry_read($entry))


fwrite($fh, $data);






header(“Location: /”);


Using it is very simple: create file installwordpress.php and copy-paste this script there and then navigate your browser to this file. All should happen automatically.

Backup large MySQL database without SSH access

mysqldumperMoving your databases around is easy when they are small. When they get large it may become a problem especially if you are on a shared hosting…

One of my website’s database grew to 5.5Gb in size. When it’s that big phpMyAdmin and standard control panel backup scripts just don’t work. Fortunately there is a great solution: MysqlDumper.de (english translation). It’s PHP/AJAX application that backs up and restores your databases part by part. It’s really straightforward to use.

It took it 10+ hours to export by 5.5Gb database as 700Mb of GZipped SQL scripts but it got the job done 100%. Another nice touch about it is that it allows you to break down your backups into parts so you can start restoring the database at the new location the moment first part is ready. This can be quite useful since when you are restoring database this big reconstructing indexes can take a very long time.

Hostgator vs. Godaddy vs. whatever rant

Just got an email from Hostagtor notifying me that one of my websites was shut down because it was using up too much CPU time on their “unlimited” shared hosting plan… Oh, well. I had no illusion ot begein with about their plans being truly unlimited but I didn’t realize that they were that limited.

I’ve been with hostgator since September 2008 and it was a great relief after ditching Godaddy. cPanel is much better than Hosting Control Center that Godaddy uses and you don’t need to wait 30+ minutes for the new database to get set up or domain to attach to hosting account. I all happens instantly as it should. Support was also faster to respond than folks at Godaddy.

However Hostgator has this nasty habbit of shutting down your websites for overusing their “unlimited” plans and only then letting you know about it.

As I moved some of my websites to Godaddy I found out that they are more tolerant to bandwidth/CPU abuse than Hostgator. However they still have all the problems I wrote above. Looks like it’s time for me to move to dedicated hosting server…

While I’m still in rant mode – one more warning – never ever host with 1and1.com – worst hosting experience I’ve had ever. In case of Godaddy and Hostgator problems at least start after your websites are up and running – with 1and1 you may not even get there. In case you are tempted to use them as domain resitrar because of their $10/year price that includes private registration – don’t. It’s not worth the trouble – if you want to update DNS servers on your domains it may take up to 24 hours…

Rant mode: off

Mysql Connector Set Variable

MySql is a nice database engine, C# is nice programming language. However when you put them together you get something not nice at all. At least from a viewpoint of someone like me who is spoiled by nice, clean and seamless database integration Linq for SQL provides for MSSQL. Unfortunately when you put together MSSQL and PHP you also get an ugly thing that doesn’t quite work.

One of the main problems with integrating MySQL with .NET languages is complete lack of documentation for MySQL Connector. CHM file that comes bundled with it is a joke – it merely lists class members and has a couple of stub articles. There are some sample pieces of code but after that you are on your own.

Just recently I ran into a problem of not being able to SQL variable from query.  If you write something like this:

using (MySqlCommand cmd = this.mySql.CreateCommand())
cmd.CommandText = “SET @today=DATE(NOW())”;
return cmd.ExecuteNonQuery();

you’ll get “Parameter ‘today’ must be defined.” exception. I searched the internet and only thing I could find was this message from mysql .net maillist with no replies. Typical shortcoming of open-source of nobody wanting to do the dirty work of documenting their code properly is somewhat offset by the fact that you can poke around the code yourself. So I did.

Solution is there but it’s anything but obvoius – append Allow User Variables=true; to your MySQL connection string. This will cause MySql connector to skip checking parameters mentioned in the query for existence. There is a downside to this solution – you’ll not be able to easily catch bugs in your code caused by mistyped query parameter names.

Hopefully at some point MySql connector developers will realize that passings parameters into query and settings MySQL connection variables are two different pieces of functionality and each should have it’s own independent syntax.

This Blog Is Live

This is a slight improvement of default WordPress “Hello, World!” post. I’ve finally ran out of excuses not to do it so I configured DNS servers and installed WordPress and should start posting useful stuff soon enough. None of it will be rocket science. However it took me some time to figure it out so hopefully it’ll save the same amount of time to folks who will read this blog.