Jan 27 10

Dropdownify – Minimal effort dropdown

by dom111

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;
}
Dec 17 09

Breaking down large CSV files

by dom111

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!

read more…

Dec 14 09

jQuery Message – Letting the user know what’s going on

by dom111

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.

Oct 20 09

Apache, Subversion and favicon.ico

by dom111

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!

Oct 7 09

PHP CSV Reader

by dom111

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.

Sep 24 09

jQuery Ajaxify – Update

by dom111

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.

Sep 24 09

DNS Issues

by dom111

Looks like this blog’s been down for a few days…

I’ve moved my DNS over to 123-reg and have had a few issues getting all the DNS records to work as expected…

Hopefully I’ve fixed it now…

Aug 27 09

CakePHP: Select Box Pagination

by dom111

Using CakePHP’s built in pagination system has saved me so much time in my current day job, but the latest designs I’m working on have drop-down box style pagination, as it’s possible to get many pages of results.

To change the named parameters in the current URL I’ve created this small javascript function that will amend the URL: read more…

Aug 26 09

CakePHP: Components, redirect fail (On my part…)

by dom111

I’ve been working on a CakePHP project lately and created a small component which was only needed in one of my controllers:

class CounterComponent extends Component {
  var $components = array(
    'Session'
  );
 
  function i() {
    if ($this->Session->check('Counter.i')) {
      $i = ($this->Session->read('Counter.i') + 1);
 
    } else {
      $i = 0;
    }
 
    $this->Session->write('Counter.i', $i);
 
    return $i;
  }
 
  function clear() {
    $this->Session->delete('Counter.i');
  }
}

read more…

Aug 26 09

Apple Mail’s inability to count over… uhh… big numbers

by dom111
Apple Mail can't count

Apple Mail can't count

I never noticed that before… I wonder what the cutoff is…

Note: I like Apple Mail, this is not a complaint!