dom111.co.uk http://www.dom111.co.uk/blog Move along. Nothing to see here. Wed, 14 Jul 2010 19:30:31 +0000 en hourly 1 http://wordpress.org/?v=3.0 Gallery 0.1 http://www.dom111.co.uk/blog/coding/gallery-0-1/245 http://www.dom111.co.uk/blog/coding/gallery-0-1/245#comments Wed, 14 Jul 2010 19:28:08 +0000 dom111 http://www.dom111.co.uk/blog/?p=245 I recently took it upon myself to create a very small gallery project to easily display images from a folder structure in a fairly pleasing way…

This is the result!

You can get the script here

]]>
http://www.dom111.co.uk/blog/coding/gallery-0-1/245/feed 0
Minify CSS – Shrink your CSS down to size http://www.dom111.co.uk/blog/coding/minify-css-shrink-your-css-down-to-size/238 http://www.dom111.co.uk/blog/coding/minify-css-shrink-your-css-down-to-size/238#comments Fri, 16 Apr 2010 18:07:11 +0000 dom111 http://www.dom111.co.uk/blog/?p=238 I know there are probably many services offering it already out there, and it’s not too hard to run right in TextMate, but I haven’t been able to find it in 30 seconds of Googling (well, I couldn’t at work, but I’ve since found this… Oh well!), so I set up a quick script to do it for me:

http://www.dom111.co.uk/files/minifycss/

If it’s useful, I might set up a memorable URL, let me know in the comments :)

I did set up syntax highlighting, using codemirror, which looked pretty nice, but made the minification (on large-ish files) take far too long. I haven’t really tested on any huge files, so try this at your own risk, but it seems faster that TextMate was.

]]>
http://www.dom111.co.uk/blog/coding/minify-css-shrink-your-css-down-to-size/238/feed 0
jQuery – Persistent Input Labels http://www.dom111.co.uk/blog/coding/jquery-persistent-input-labels/236 http://www.dom111.co.uk/blog/coding/jquery-persistent-input-labels/236#comments Thu, 01 Apr 2010 08:03:58 +0000 dom111 http://www.dom111.co.uk/blog/?p=236 Do you forget whats supposed to go in the field the second you tab onto it?

Are you concerned your users will too?

Never fear! This simple plugin places an element of the same type underneath the current element and shows the contents of the title attribute (or whatever attribute you decide to use) as a label until you type text into the box!

It’s a very early version, and probably has a few bugs, but I’ve implemented enough to make it fairly useful I think. Unfortunately when you resize a textarea in webkit, it doesn’r fire the resize event, so I’ve added a workaround using mousemove (I tried to only capture mousemove if a mousedown had been detected, but to no avail…)

You can see a demo here, and get the files here.

]]>
http://www.dom111.co.uk/blog/coding/jquery-persistent-input-labels/236/feed 0
XML Entities in PHP http://www.dom111.co.uk/blog/coding/xml-entities-in-php/224 http://www.dom111.co.uk/blog/coding/xml-entities-in-php/224#comments Mon, 15 Feb 2010 20:34:35 +0000 dom111 http://www.dom111.co.uk/blog/?p=224 Because htmlentities() doesn’t even come close.

This small file contains 4 functions (2 of which are taken from the PHP manual, credit given!) which will allow you to encode and decode entities from ASCII/unicode strings in either decimal or hexadecimal format for use in valid XML documents.

The xml_entity_decode() function accepts an optional second parameter to allow non-standard XML entities (that may have been specified in your schema) in the format:

array(
  // 'entity' => 'char'
  'amp' => '&',
  'lt' => '<',
  'gt' => '>',
  'apos' => '\'',
  'quot' => '"'
)

Example usage:

include('funcs.xmlentities.php');
 
$s = '<strong>This</strong> should be safe, but don\'t assume!<br/>';
print '<Field>'.xmlentities($s).'</Field>';
// outputs: <Field>&lt;strong&gt;This&lt;/strong&gt; should be safe, but don&apos;t assume!&lt;br/&gt;</Field>

You can get the script here, or there’s a demo here too.

]]>
http://www.dom111.co.uk/blog/coding/xml-entities-in-php/224/feed 0
Dropdownify – Minimal effort dropdown http://www.dom111.co.uk/blog/coding/dropdownify-minimal-effort-dropdown/218 http://www.dom111.co.uk/blog/coding/dropdownify-minimal-effort-dropdown/218#comments Wed, 27 Jan 2010 12:19:38 +0000 dom111 http://www.dom111.co.uk/blog/?p=218 So recently I was asked to change a navigation style of an existing site to drop-down menus.

Simple, I thought, just use one of the many existing drop-down plugins. I tried many, but most seemed to use hardcoded styles and I had a few problems (some of which I encountered again, writing this).

So I’ve made this, I think it’s fairly robust, but I’m sure there’ll be problems with embedded objects (flash) and select boxes (in <= IE6), but for my needs, it sufficed, so I thought I'd share, in case anyone else needs a simple script to manage drop-downs.

To use, create a nest of elements like this:

<ul id="top">
  <li>
    <ul>
      <li></li>
    </ul>
  </li>
</ul>

or something similar (any elements, should work) and call:

// jQuery:
$('ul#top').dropdownify();
 
// mootools
$('top').dropdownify();

Which should create a simple drop-down.

There are a couple of examples, one for jQuery and one for mootools, and the files can downloaded here and here.

I did encounter a problem with IE, mainly due to z-index faults, so with HTML code like the following:

<div class="nav-wrapper">
  <ul id="top">
    <li>
      <ul>
        <li></li>
      </ul>
    </li>
  </ul>
</div>

I used the following CSS:

div.nav-wrapper,
div.nav-wrapper ul,
div.nav-wrapper ul li {
  position: static;
  z-index: 100;
}
]]>
http://www.dom111.co.uk/blog/coding/dropdownify-minimal-effort-dropdown/218/feed 0
Breaking down large CSV files http://www.dom111.co.uk/blog/coding/breaking-down-large-csv-files/214 http://www.dom111.co.uk/blog/coding/breaking-down-large-csv-files/214#comments Thu, 17 Dec 2009 13:53:51 +0000 dom111 http://www.dom111.co.uk/blog/?p=214 Today I received a 45Mb CSV file for importing into a database… Needless to say the application we were importing to didn’t seem to like the size of the file, for what ever reason… So I knocked up a quite bash script to create smaller ‘chunks’ defined as a number of lines, to make importing simpler.

I’m sure there’s many way in which is can be simplified, so if you know any I’d like the contributions!

It’s run like this:

$ ./csv-chunk.sh large-data.csv 5000

The first argument being the filename and the second argument the maximum number of lines for each ‘chunk’. From that 45Mb megalith, 38 files of around 1.2Mb were produced which didn’t seem to break the other end!

Here’s the script:

#!/bin/bash
 
function help {
  echo "Usage:"
  echo "  $0 <csv filename> <number of lines>=5000"
  exit 1
}
 
if [ $# -eq 0 ]; then
  help
fi
 
if [ $# -eq 1 ]; then
  chunk=5000
else
  chunk=$2
fi
 
file=$1
 
if [ ! -e $file ]; then
  echo "File $file not found!"
  exit 5
fi
 
header=`head -n 1 $file`
max=`cat $file | wc -l`
x=1
 
echo "Breaking down $file ($max lines into $chunk lined files)"
 
for (( i=1; i<=$max; i+=$chunk )); do
  chunkfile="chunk-$x-$file"
 
  if [ -e $chunkfile ]; then
    echo "$chunkfile already exists!"
    exit 2
  fi
 
  `touch $chunkfile`
  echo $header > $chunkfile
 
  start=`expr $i + 1`
  end=`expr $i + $chunk`
 
  `sed $start,$end\!d $file >> $chunkfile`
 
  x=`expr $x + 1`
done
 
echo "Created $x files"
exit 0
]]>
http://www.dom111.co.uk/blog/coding/breaking-down-large-csv-files/214/feed 0
jQuery Message – Letting the user know what’s going on http://www.dom111.co.uk/blog/coding/jquery-message-letting-the-user-know-whats-going-on/209 http://www.dom111.co.uk/blog/coding/jquery-message-letting-the-user-know-whats-going-on/209#comments Mon, 14 Dec 2009 09:40:14 +0000 dom111 http://www.dom111.co.uk/blog/?p=209 Screenshot

Recently I’ve seen a few implementation of Growl in Javascript and basically just thought I’d have a go too. Everyone’s doing it, or so it seems!

This simple implementation is styled using pure CSS and you should be to easily modify it to suit your needs!

I’ve set up a demo page and the files can be grabbed from here.

]]>
http://www.dom111.co.uk/blog/coding/jquery-message-letting-the-user-know-whats-going-on/209/feed 0
Apache, Subversion and favicon.ico http://www.dom111.co.uk/blog/apple/apache-subversion-and-favicon-ico/205 http://www.dom111.co.uk/blog/apple/apache-subversion-and-favicon-ico/205#comments Tue, 20 Oct 2009 11:20:07 +0000 dom111 http://www.dom111.co.uk/blog/?p=205 I discovered a strange error in my apache logs today:

[Tue Oct 20 11:04:10 2009] [error] [client 12.34.56.78] (20014)Internal error: Can't open file '/.../svn/repositories/favicon.ico/format': No such file or directory
[Tue Oct 20 11:55:55 2009] [error] [client 12.34.56.78] Could not fetch resource information.  [500, #0]
[Tue Oct 20 11:55:55 2009] [error] [client 12.34.56.78] Could not open the requested SVN filesystem  [500, #2]
[Tue Oct 20 11:55:55 2009] [error] [client 12.34.56.78] Could not open the requested SVN filesystem  [500, #2]

Most of my Google searches returned issues where people couldn’t view their repositories, but I could see mine fine…

Then I looked at the error messages again and noticed it was looking for a repository called favicon.ico. A quick Google later and I found this page:

http://www.trilithium.com/johan/2005/02/no-favicon/

Adding the suggested items to my Apache conf fixed the problem!

]]>
http://www.dom111.co.uk/blog/apple/apache-subversion-and-favicon-ico/205/feed 0
PHP CSV Reader http://www.dom111.co.uk/blog/coding/php-csv-reader/201 http://www.dom111.co.uk/blog/coding/php-csv-reader/201#comments Wed, 07 Oct 2009 19:08:22 +0000 dom111 http://www.dom111.co.uk/blog/?p=201 I’ve never really built a definitive CSV reader and end up building a quick implementation of one any time I need one.

But after working on the chunk script I decided that next time I build a CSV class I’d do it properly.

This is the result:

  <?php
  require('class.csv.php');
 
  header('Content-type: text/plain');
 
  $csv = new CSV('test.csv');
 
  while ($row = $csv->read()) {
    print_r($row);
  }

There’s an information page here, and the script is here.

]]>
http://www.dom111.co.uk/blog/coding/php-csv-reader/201/feed 0
jQuery Ajaxify – Update http://www.dom111.co.uk/blog/coding/jquery-ajaxify-update/191 http://www.dom111.co.uk/blog/coding/jquery-ajaxify-update/191#comments Thu, 24 Sep 2009 14:17:56 +0000 dom111 http://www.dom111.co.uk/blog/?p=191 I’ve been doing more work on the jQuery AJAXify plugin, it’s now a lot more robust (I think…) and I’ve squashed a few bugs that were in the previous version (with help from Andrea Battaglia) along with adding in a few new features (with their own bugs no doubt!).

Theres an updated test page and as ever a direct link to download here.

Check out the test page to see the new features!

Edit: Further updates, all links have been updated to version 0.3b. Added (and documented existing) callbacks as requested by Sebioff! And a further fix for the ‘append’ option. Also fixed IE6 compatibility.

Further Update: Another update after the comment from David Lee about $(‘form’).serialize();

Another Further Update: I have set up a Google Code repository for this plugin, which states that this code is released under the MIT license.

]]>
http://www.dom111.co.uk/blog/coding/jquery-ajaxify-update/191/feed 16