CHM should be in…

Well… Long time… But finally a new post!

If You have drank Linux KoolAid, then You can run on problems when You get some CHM file. It is old format and I think it has place where it can live (like many other proprietary data formats):

Place where we should send .chm files
Place where we should send .chm files (c) Marcin Wichary

But still, You can get documentation in such format, chances are high if You are trying to interface some .Net SOAP service. In Linux – no viewer for CHM.

Or rather no standalone viewer. There is solution – CHM Reader addon for Firefox. It is not perfect (no global search), but allows to navigate through that file. Printouts to PDF usually are stripped from hyperlinks, so navigating through 800 pages is reason why PDF printout is not an option…

Thumbnails are missing when uploading new image

Just a quick note – if You are experiencing missing thumbnails in image upload in WordPress, then probably Your PHP installation misses php-gd module.

It is module by default installed on FreeBSD, but on Debian based Linux You have to add it by hand (apt-get install php5-gd).

I had to move my blogs to new, temporary host, with Linux on board instead of FreeBSD. Then I have noticed that when I want to publish new post I can only insert in it uploaded image in original size – not very handy. It took 15 minutes of googling and finally dive into wp-includes/media.php to check how these thumbnails are generated.

Email verification – regexp

Many times before when I was supposed to collect emails from users I was googling to find some regexp to verify email syntax. At least I was aware that regexp challenging email address syntax is a bullshit ;) I was working few years as Unix sysadmin mostly on mail servers, so I had some idea how RFCs related to email are bloated ;) and contain so many exceptions ;)

Step back and think again
Step back and think again. Image CC by Vivianna_love

From some time I do use following regexp to verify email address:

 /.+@.+[.].+/

This should check if:

  • there is @ sign somewhere inside
  • at least one character is before @ sign
  • at least 3 chars (with one dot) are after @ sign

Why such simple rules? I have found comment on StackOverflow, that man should step back and think why is checking email address?

I want just to help users and stop them making simple mistakes in theirs emails. Like not providing @ at all. Or eating .com in gmail.com address. And that’s it – email will be probably shortly after that verified with only reliable method via sending email to this address.

And if You insist to verify emails with more strict regular expression, please do remember that plus sign is perfectly valid character before @. Many regexps found via google are forgetting that…

Extracting fixtures

I’m still using fixtures. Shame, I know.

Why I do use them instead of Factory Girl or other solution like that? Well, fixtures can be much more closer to real data than mocks from Factory. How come, You ask? Fixtures are imaginary data exactly like mocks from other sources!

My answer is: that depends how You create fixtures. If You create them by hand, indeed they are disconnected from real world (like all mocks).

What is Your real data/mocks ratio?
What is Your real data/mocks ratio? CC by hsing

But I prefer to extract fixtures from real (production) database. That way I can easily pick entries created by users which are edge cases. The only trouble is with creating fixtures. For some time I’m using modified extract_fixtures rake task. I have added some conditions to extracting process – SQL condition to select only particular records and adjusted syntax to recent rake.

This is useful especially when You are about to take over application code which has no tests. Extracting real data is quick way to start write integration tests (in such case they have are most efficient – time invested and application code coverage).

How to extract fixtures without pain?

Continue reading “Extracting fixtures”