jQuery tools scrollable: Uncaught TypeError: Cannot set property ‘ontouchstart’ of undefined

I recently was getting the following error when calling .scrollable(); on a div using jQuery tools 1.2.5 and jQuery 1.4.4

Uncaught TypeError: Cannot set property 'ontouchstart' of undefined

My scrollable structure was set up in the following way:

    <div class="ss_scrollable">
        <div class="ss_items">
                    <div class="item_set">
                          <img src="item_one.png"/>
                    <div class="item_set">
                          <img src="item_two.png"/>
        <a class="prev browse left" href="#" onclick="return false;"></a>
        <a class="next browse right" href="#" onclick="return false;"></a>

I was able to fix the error by moving the next and previous links outside of the ss_scrollable div.

Uploadify stalling on uploads on Internet Explorer 8

For some reason, calling .hide() on my #uploadify div was causing uploads to stall after the #uploadify div was shown.

Very strange bug, eh? The hacky solution is instead to use div.height on #file_uploadUploader instead of .hide() and .show() on #uploadify

// To hide uploadify
// To show uploadify

If you want to hide #file_uploadUploader when the page loads, use the onSWFReady callback.

Hope this saves someone a headache.

Galleriffic IE 7 Fix: Images not showing

I had an issue where Galleriffic was not displaying the current image correctly. Searching around, it seems like others have had this issue as well.

The fix for me was simple, I just added the following to my CSS and it worked:

div.slideshow img
    position: relative;

Passing GET parameters to CakePHP’s paginator

I had an issue where I had a search page which relied on GET parameters. When I added CakePHP’s pagination, the paginator did not pass along my GET variables.

Here’s my solution:

$urlParams = $this->params['url'];
$this->Paginator->options(array('url' => array('?' => http_build_query($urlParams))));

CakePHP Table Helper

Recently, I’ve been developing a lot of sites that require the creation of a table that lists entries and has links to actions. In order to speed up development, I created a helper for CakePHP to create these tables for me.

For example, let’s say I have a list of properties in the form:

    [0] => Array
            [Property] => Array
                    [id] => 12
                    [address_id] => 96
                    [description] => An okay apartment
                    [price] => 300
                    [type] => apartment
                    [num_bedrooms] => 1
            [Address] => Array
                    [id] => 96
                    [address1] => 650 Columbus Ave
                    [address2] => 
                    [city] => Boston
                    [state] => MA
                    [zip] => 1104
    [1] => Array
            [Property] => Array
                    [id] => 19
                    [address_id] => 98
                    [description] => One great apartment
                    [price] => 500
                    [type] => apartment
                    [num_bedrooms] => 1
            [Address] => Array
                    [id] => 98
                    [address1] => 731 Parker St.
                    [address2] => 
                    [city] => Roxbury Crossing
                    [state] => MA
                    [zip] => 1104

I’d like to use the table creator to create a table which lists all the entries and provides action links to view the property and to edit the address. To do so, I include the helper in my controller, and then use the following code in my view.

Note that the createTable function takes in five parameters:
– the default model name
– the entries for the table
– the columns for the header. An associative array with Column Name => Database field
– the actions for the columns. An array in the form Action Name => (Action URL, Action database field)
– text to display when there are no entries.

$displayFields = array('Type' => 'type',
                       'Address1' => 'Address.address1',
                       'City' => 'Address.city',
                       'State' => 'Address.city',
                       'Price' => 'price',
                       'Bedrooms' => 'num_bedrooms');
$actions = array('View' => array('/properties/view/', 'Property.id'),
                 'Edit Address' => array('/address/edit/', 'Address.id'));
echo $this->Table->createTable('Property',
                               'You currently have no properties listed'

This code generates the following table:

For the first entry, the ‘View’ link goes to /properties/view/12 and the ‘Edit Address’ link goes to /address/edit/96.

Having this helper has definitely increased my productivity in making a lot of CRUD-based admin areas. I hope you find it helpful too. To download the source code and use it yourself, check out the github repository.

On the road to remote SVN syncing: svn_directory_sync.py

Fore more than one project that I’m working on right now, I’m managing the source code using Subversion. Unfortunately, I only have FTP access to the production server that the code lives on. Therefore, it’s not a trivial process to update the code on the production server to the latest revision.

Many of the repositories are very large, and therefore it’s too time and bandwidth consuming to re-upload the entire directory. I attempted to use weex to sync my local repository with the FTP server, but ran into two issues:

  • Weex sometimes timesout and throws errors while creating directories
  • Weex takes a long time for large repositories with deep file structures

Eventually, I’d like to write a complete alternative solution to weex in python with direct SVN integration. But, for now, I’ve written svn_directory_sync: a python script that makes things a bit easier.

For now, I keep a log of what subversion repository is on the production FTP server. Then, I use svn_directory_sync to move all the files that have been modified or added to the repository since the production revision to a separate local folder on my development machine. I can then upload those files manually or use weex to sync that ftp folder (setting weex to not delete remote files if they are not in the local folder).

For example, let’s say I have a local copy of a svn repository located at ~/www/mywebsite. I last updated the production server at revision 60. Since then, I’ve made several subversion commits: I’ve modified two files and added one directory and added one file to the local subversion repository. I now can run the following command to put those files in a separate folder to upload manually or using weex.

I run the following command, telling svn_directory_sync to move the modified and added files since revision 60 into a new folder located at ~/tmp/files_to_upload

python svn_directory_sync.py -s ~/www/mywebsite/ -o ~/tmp/files_to_upload -r 60

The script then outputs:

Copying /home/steve/www/mywebsite/modified_file1.html to /home/steve/tmp/files_to_upload/modified_file1.html
Copying /home/steve/www/mywebsite/modified_file2.html to /home/steve/tmp/files_to_upload/modified_file2.html
Creating directory /home/steve/tmp/files_to_upload/new_directory
Copying /home/steve/www/mywebsite/new_directory/newfile.html to /home/steve/tmp/files_to_upload/new_directory/newfile.html

You can now manually upload the files in ~/tmp/files_to_upload to the web server or use weex to sync the local and remote folders.

To download the script and view the source check out svn_directory_sync on github

CakePHP Use validation rule outside model

Recently I wanted to incorporate CakePHP’s URL validator inside my own validation rule. To do this, I used App::Import. This allows you to use CakePHP’s validation rules inside your own validation rule, or wherever you want.

App::import('Core', 'Validation');
$isStrictUrl = Validation::url($value, true);

CakePHP: Get pagination page count as variable, Hide page count if only one page

This isn’t mentioned in the CakePHP book, but you can get the number of pages in a pagination by using the following code:

$this->params['paging'][<MODEL NAME>]['pageCount']

I recently used this to only display a page count if there is more than one page. Below is the code, note that my model name is “Property” in this example.

$hasPages = ($this->params['paging']['Property']['pageCount'] > 1);
if ($hasPages)
    echo $this->Paginator->counter();

Target Filesystem doesn’t have /sbin/init – Ubuntu 10.04

My parent’s computer recently refused to boot, with the error message “Target Filesystem doesn’t have /sbin/init”, following by booting to BusyBox.

I was able to fix this by:
– Booting into Ubuntu from a Live CD
– Going into GParted and figuring out what the mount location of my linux partiton is on (it was /dev/sda6).
– Then running the following command from the terminal:

e2fsck -f -y -v /dev/sda6

This command repaired the file system, and when I rebooted Ubuntu was working again.

Install XMonad with Gnome on Ubuntu 10.04 as a separate session

I tried doing this for a while, and a lot of the blog posts and tutorials did not work, or they did not allow me to choose between Xmonad+Gnome and just Gnome on login.

The closest one I found that worked was http://miggysmith.wordpress.com/2010/10/03/xmonad-and-gnome/ Below you’ll find my slightly modified version.

First, get xmonad using:

sudo apt-get install xmonad

This installs xmonad and gives an entry in our xsessions. But, we need to do some work to have xmonad and gnome work together.

First, let’s create ~/.xmonad/xmonad.hs and paste the following into it:

import XMonad
import XMonad.Util.EZConfig
import XMonad.Config.Gnome
main = xmonad $ gnomeConfig { terminal = "gnome-terminal" }

This tells xmonad to use the gnomeConfig they’ve supplied, and additionally to use the gnome terminal.

Now, let’s create a custom startup script to get xmonad and gnome to work together. You can create the script wherever. Since I’m the only user on this machine, I created mine in ~/xmonadstart.sh

Paste the following code in your ~/xmonadstart.sh script:

export WINDOW_MANAGER=xmonad
gconftool-2 -u /desktop/gnome/session/required_components/windowmanager

This tells gnome to use the xmonad window manager. Also, it unsets the current windowmanager in gconf. Other tutorials forgot to mention to do this! Finally, it starts gnome-session which now uses xmonad.

In order for this to work we need to make the script executable, so run:

chmod +x ~/xmonadstart.sh

We’re almost done. The last step is to modify /usr/share/xsessions/xmonad.desktop. Change it the following:

[Desktop Entry]
Comment=Lightweight tiling window manager

This tells xmonad to run the custom xmonadstart.sh script.

Now we’re done. Logout, click your username to login, and on the bottom choose ‘Xmonad’ from the sessions. You should be running xmonad within gnome! You’ll notice there aren’t title bars on windows and things have a red border. See the Default Keyboard Bindings to start understanding how xmonad works.

Customizing XMonad while keeping gnome configurations
If you’d like to go a bit farther, here’s my customized xmonad.hs which keeps the gnome configurations. It changes xmonad so that when you cycle through layouts (mod space), you cycle through the default “tiled” layout and then you cycle through a full screen tabbed layout.

import XMonad
import XMonad.Util.EZConfig
import XMonad.Config.Desktop
import XMonad.Config.Gnome
import XMonad.Layout.Tabbed
myLayout = (desktopLayoutModifiers $ tiled) ||| simpleTabbed
    -- default tiling algorithm partitions the screen into two panes
    tiled   = Tall nmaster delta ratio
    -- The default number of windows in the master pane
    nmaster = 1
    -- Default proportion of screen occupied by master pane
    ratio   = 1/2
    -- Percent of screen to increment by when resizing panes
    delta   = 3/100
main = xmonad $ gnomeConfig{ terminal = "gnome-terminal",layoutHook = myLayout}