Development


13
Jan 12

Cheeky Hidden Advert

I use www.lipsum.com on a regular basis to get placeholder text when mocking up a website. You enter the number of paragraphs you want, and are presented with that many paragraphs of lorem ipsum boilerplate text which you can copy and paste as needed. Today though, I noticed a cheeky recruitment advert in the lorem ipsum. Thinking it was a mistake in copy and pasting, I entered and re cut and paste, only to get the same advert in my text.

A quick inspection of the site with Firebug showed a bit of hidden text that gets picked up when you copy and paste. The slight annoyance was offset by the cheekyness, and I learnt a new little trick today!

 


21
Dec 11

Spliting strings with awk / nawk

I mainly use nawk to extract elements from a string where I know the position (eg to get just the filenames when running a grep and I’m just too lazy to remember the correct grep syntax).

so, to extract field number x from strings in where the field separator (FS) is y:

$ nawk '{ FS="y"; print $x }'

17
Dec 11

Fixing pg Gem problem on Ubuntu 11.04

I’ve been getting errors relating to the pg gem when running

$ bundle install

on a RoR application I’ve been testing locally.

here’s the error:

Installing pg (0.11.0) with native
extensions /home/christian/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:551:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/home/christian/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
 checking for pg_config... no
 No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
 checking for libpq-fe.h... no
 Can't find the 'libpq-fe.h header
 *** extconf.rb failed ***
 Could not create Makefile due to some reason, probably lack of
 necessary libraries and/or headers. Check the mkmf.log file for more
 details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/christian/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config

To fix, I ran the following:

$ sudo aptitude install 1ibpq-dev

followed by:

$ gem install pg

I can now bundle the application successfully.


21
Nov 11

Split Window in Aptana Studio

If you’re editing a large file of code and you need to reference two area of the code at the same time, it can be useful to split the window into two separate area of code.  To do this in Aptana Studio 3:

  1. Right click on an editor tab
  2. Choose “New Editor”
  3. Drag one editor tab to the bottom or side of your editor area

21
Nov 11

Checking for a valid domainname

Very quick function to test a domain name is valid:

    function validDomain($domain)
    {
        // Test domain is actually valid
        if (preg_match('/^[a-z]+([a-z0-9-]*[a-z0-9]+)?(\.([a-z]+([a-z0-9-]*[a-z0-9]+)?)+)*$/i', $domain))
        {
            return TRUE;
        }
        return FALSE;
    }

The key here is the regular expression (delimited by the forward slashes at each end):

/^[a-z]+([a-z0-9-]*[a-z0-9]+)?(\.([a-z]+([a-z0-9-]*[a-z0-9]+)?)+)*$/

This basically translates as follows

  • ^[a-z]+    : First chacter must be alphabet
  • ([a-z0-9-]*[a-z0-9]+)    : A group. The first character may be in the range, a-z or 0-9, or a hyphen. This pattern can repeat, although the last character may not be a hyphen
  • ?    :  That last group is optional
  • (\.     :  Start of next group, and it must be a dot
  • ([a-z]+ : First letter must be in range a-z
  • ([a-z0-9-]*[a-z0-9]+)?  :  Then an optional group of a-z, 0-9 and hypen, though last  character may not be hyphem (as above)
  • )+)  : Do the last bit at least once
  • :  The last bit is optional and can repeat as much as you like
  • $:   And that’s the end of the string

It’s not a perfect reg-exp for the job, but it does the job where a quick quick is required (user signups fro example), rather than mission critical domain testing.

A good tool for testing your regular expressions can be found here

 


21
Nov 11

View files changed in a specific commit

A simple task…To get a list of files that have changed in a specific svn commit:

svn log -v -r <commit-no>

The log command returns broad information about a commit (or list of commits) – date, author and changed paths

-v  (or –verbose) give detailed output

-r  displays information about a specific commit only

 


23
Oct 11

The Ruby Show

Just subscribed to The Ruby Show podcast, presented by Jaison Seifer and ‘Beginning Ruby’ author Peter Cooper.  Nicely presented and well worth a listen.