1 0 Archive | programming RSS feed for this section
post icon

RubyProf error “can’t convert Fixnum into String”

I recently maxxxxed out my memory limit on my regular dreamhost account at work causing 500 errors all over the place. This is now forcing me to start learning how to cache, and trace my apps for memory and performance. I also switched to PS with 300mb burstable to around 700mb. That should help out for now. Anyway, back to finding out which requests are drinking redbull… I installed the ruby-prof gem to find out. I ran a request with the param key added to the end of the url and wham! Errors? WTF? I copied the code right out of “Advanced Rails Recipes” correctly, and checked it 10 times? So what’s the error? “can’t convert Fixnum into String”? Well it seems that the printer class is trying to convert a number to a string, which just won’t happen. It was pretty obvious what was happening:

response.body << printer.print("", 0)

Right there! It’s trying to append the request body to the printer class with a integer passed as a hash. I haven’t looked at the ruby-prof code but the class doesn’t like that. So I just put quotes around it.

response.body << printer.print("", '0')

Then it worked out fine! Hope that helps someone out cause I spent about 2 hours searching for the problem.

Leave a Comment
post icon

My Top Five Favorite Plugins For Rails

There are some pretty sweet plugins out there for Ruby on Rails, but being a beginer with this frame work I’ve found and used these five the most. In no particular order:

1) ATTACHMENT_FU:

Hmmmm, how do you say? Image, photo, graphic management with only writing about 10 lines of code? How bout, BOO YA YIPPIE WOO HOO go suck it PHP! JK I still love you php but just not like Ruby on Rails.

2) DELAYED_JOB

Delayed job is a plugin that let you send or offload processes into the background, so if you have a script that would normally take extremely long to do and don’t want the user waiting till it’s finished this is a plugin you want to checkout.

3) WILL_PAGINATE:

Wow a plugin for pagination! And I’m only writing: <%= will_paginate @subscribers %> Holly woowsers where do I sign up?

4) RESTFUL_AUTHENTICATION:

So authenticating can be downright hard, confusing and annoying… well to do it right and with no security flaws that is. So why not just use someone’s tried, testing and tough like a champ code that allows for admin authentication, sign up activation and more? This plugin rules and your only writing one line of code to tell it which methods should be closed to the public. It also gives you a wacka load of helpful methods to use all over your application.

5) PERMALINK_FU:

This is one cool plugin. When you have a CMS and you allow for people to add; lets say pages to their site, you can use this plugin by putting a line of code or two in your model to automatically create a friendly url. Example: Page called “This Plugin Rocks!” will create a url called this-plugin-rocks! It’s really that simple.

6) WHENEVER

Run scripts, rake tasks etc like cronjobs in pure Ruby. This is much easier than modifying your crontab. This plugin does it for you.

7) CACHE_FU

If you want caching and use memcache, this is a sweet plugin to checkout, although the documentation isn’t very good, you can do a ton of great caching with this cache_fu.

8) FACTORY_GIRL

Factories not fixtures? Yes please, write factories that make it way way easier for you to maintain data in Rails tests.

Leave a Comment
post icon

Modifying Textmate drawer font size

If you are like me and hate how small the font’s are in Textmates drawer, don’t get mad get modificlisious. You must have Xcode installed. Don’t worry about messing around with Interface builder files for apps because when you save the nibs they save a backup. Here’s how to modify the font size in Textmates drawer:

  • Browse to the application and right click or ctrl click => show package content
  • Go Contents/Resources/English.lproj/ => open Project.nib
  • In the project window double click on the FileHierarchy icon
  • Now the FileHierarchy window should open so click on the drawer in the FileHierarchy window
  • Press Apple T or go Format => show fonts from the menu set
  • Now just select the font you want to use and the size
  • You should see the fonts change
  • Save and relaunch Textmate!
Leave a Comment
post icon

Pimp my text mate or other mac apps UI

Subtle Gradient has a post about pimping out your favorite mac os apps ui’s. Think I’ll be hitting up the hack for my Text Mate ui. I hate that the fonts and colors in the drawer don’t match my editing area and I also hate how small the fonts are. I have my fonts jacked up to 16 so that I don’t throw my back out every time I want to code from leaning into my computer screen!

Leave a Comment
post icon

Compiling a custom php5 install with ming on dreamhost

Due to recent developing using php Ming library for creating Flash, I was forced to figure out how to do a custom php5 install on my Dreamhost account. It actually wasn’t hard at all considering they have well written instructions on the Dreamhost wiki. However this custom install described there doesn’t include the Ming component that I needed… so, if you need Ming here is the script I ran. I just added some lines to the script that’s listed on that page. I also upgraded the php version to 5.2.4. Everything else was the same. Here is a link to the file: custom php5.2.4 with ming library install on dreamhost, if you would like to download it.

#!/bin/sh
# Script updated 2006-12-25 by Carl McDade (hiveminds.co.uk) to allow memory limit and freetype
# Modified on 2008-02-18 by Darren Terhune (headfirstproductions.ca) to to include ming library
# Script updated 2007-11-24 by Andrew (ajmconsulting.net) to allow 3rd wget line to pass
# LIBMCRYPT version information (was set as static download file name previously.)
#
# Save the code to a file as *.sh
# Abort on any errors
#
set -e
# The domain in which to install the PHP CGI script.
export DOMAIN="headfirstproductions.ca"
# Where do you want all this stuff built? I'd recommend picking a local
# filesystem.
# ***Don't pick a directory that already exists!***  We clean up after
# ourselves at the end!
SRCDIR=${HOME}/source
# And where should it be installed?
INSTALLDIR=${HOME}/php5
# Set DISTDIR to somewhere persistent, if you plan to muck around with this
# script and run it several times!
DISTDIR=${HOME}/dist
# Pre-download clean up!!!!
rm -rf $SRCDIR $DISTDIR
# Update version information here.
PHP5="php-5.2.4"
LIBICONV="libiconv-1.11"
LIBMCRYPT="libmcrypt-2.5.7"
LIBXML2="libxml2-2.6.27"
LIBXSLT="libxslt-1.1.18"
MHASH="mhash-0.9.7.1"
ZLIB="zlib-1.2.3"
CURL="curl-7.14.0"
LIBIDN="libidn-0.6.8"
CCLIENT="imap-2004g"
CCLIENT_DIR="imap-2004g" # Another pest!
FREETYPE="freetype-2.2.1"
MING="ming-0.3.0"
# What PHP features do you want enabled?
PHPFEATURES="--prefix=${INSTALLDIR} \
--with-config-file-path=${INSTALLDIR}/etc/php5/${DOMAIN} \
--enable-fastcgi \
--enable-force-cgi-redirect \
--with-xml \
--with-libxml-dir=${INSTALLDIR} \
--with-freetype-dir=${INSTALLDIR} \
--enable-soap \
--with-openssl=/usr \
--with-mhash=${INSTALLDIR} \
--with-ming=${INSTALLDIR} \
--with-mcrypt=${INSTALLDIR} \
--with-zlib-dir=${INSTALLDIR} \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-gd \
--enable-gd-native-ttf \
--enable-memory-limit
--enable-ftp \
--enable-exif \
--enable-sockets \
--enable-wddx \
--with-iconv=${INSTALLDIR} \
--enable-sqlite-utf8 \
--enable-calendar \
--with-curl=${INSTALLDIR} \
--enable-mbstring \
--enable-mbregex \
--with-mysql=/usr \
--with-mysqli \
--without-pear \
--with-gettext \
--with-imap=${INSTALLDIR} \
--with-imap-ssl=/usr"
# ---- end of user-editable bits. Hopefully! ----
# Push the install dir's bin directory into the path
export PATH=${INSTALLDIR}/bin:$PATH
#setup directories
mkdir -p ${SRCDIR}
mkdir -p ${INSTALLDIR}
mkdir -p ${DISTDIR}
cd ${DISTDIR}
# Get all the required packages
wget -c http://us.php.net/distributions/${PHP5}.tar.gz
wget -c http://mirrors.usc.edu/pub/gnu/libiconv/${LIBICONV}.tar.gz
wget -c http://easynews.dl.sourceforge.net/sourceforge/mcrypt/${LIBMCRYPT}.tar.gz
wget -c ftp://xmlsoft.org/libxml2/${LIBXML2}.tar.gz
wget -c ftp://xmlsoft.org/libxml2/${LIBXSLT}.tar.gz
wget -c http://superb-west.dl.sourceforge.net/sourceforge/mhash/${MHASH}.tar.gz
wget -c http://www.zlib.net/${ZLIB}.tar.gz
wget -c http://curl.haxx.se/download/${CURL}.tar.gz
wget -c http://kent.dl.sourceforge.net/sourceforge/freetype/${FREETYPE}.tar.gz
wget -c ftp://alpha.gnu.org/pub/gnu/libidn/${LIBIDN}.tar.gz
wget -c ftp://ftp.cac.washington.edu/imap/old/${CCLIENT}.tar.Z
wget -c http://superb-east.dl.sourceforge.net/sourceforge/ming/${MING}.tar.gz
echo ---------- Unpacking downloaded archives. This process may take several minutes! ----------
cd ${SRCDIR}
# Unpack them all
echo Extracting ${PHP5}...
tar xzf ${DISTDIR}/${PHP5}.tar.gz
echo Done.
echo Extracting ${LIBICONV}...
tar xzf ${DISTDIR}/${LIBICONV}.tar.gz
echo Done.
echo Extracting ${LIBMCRYPT}...
tar xzf ${DISTDIR}/${LIBMCRYPT}.tar.gz
echo Done.
echo Extracting ${LIBXML2}...
tar xzf ${DISTDIR}/${LIBXML2}.tar.gz
echo Done.
echo Extracting ${LIBXSLT}...
tar xzf ${DISTDIR}/${LIBXSLT}.tar.gz
echo Done.
echo Extracting ${MHASH}...
tar xzf ${DISTDIR}/${MHASH}.tar.gz
echo Done.
echo Extracting ${ZLIB}...
tar xzf ${DISTDIR}/${ZLIB}.tar.gz
echo Done.
echo Extracting ${CURL}...
tar xzf ${DISTDIR}/${CURL}.tar.gz
echo Done.
echo Extracting ${LIBIDN}...
tar xzf ${DISTDIR}/${LIBIDN}.tar.gz
echo Done.
echo Extracting ${CCLIENT}...
uncompress -cd ${DISTDIR}/${CCLIENT}.tar.Z |tar x
echo Done.
echo Extracting ${FREETYPE}...
tar xzf ${DISTDIR}/${FREETYPE}.tar.gz
echo Done.
echo Extracting ${MING}...
tar xzf ${DISTDIR}/${MING}.tar.gz
echo Done.
# Build them in the required order to satisfy dependencies.
#libiconv
cd ${SRCDIR}/${LIBICONV}
./configure --enable-extra-encodings --prefix=${INSTALLDIR}
# make clean
make
make install
#libxml2
cd ${SRCDIR}/${LIBXML2}
./configure --with-iconv=${INSTALLDIR} --prefix=${INSTALLDIR}
# make clean
make
make install
#libxslt
cd ${SRCDIR}/${LIBXSLT}
./configure --prefix=${INSTALLDIR} \
--with-libxml-prefix=${INSTALLDIR} \
--with-libxml-include-prefix=${INSTALLDIR}/include/ \
--with-libxml-libs-prefix=${INSTALLDIR}/lib/
# make clean
make
make install
#zlib
cd ${SRCDIR}/${ZLIB}
./configure --shared --prefix=${INSTALLDIR}
# make clean
make
make install
#libmcrypt
cd ${SRCDIR}/${LIBMCRYPT}
./configure --disable-posix-threads --prefix=${INSTALLDIR}
# make clean
make
make install
#libmcrypt lltdl issue!!
cd  ${SRCDIR}/${LIBMCRYPT}/libltdl
./configure --prefix=${INSTALLDIR} --enable-ltdl-install
# make clean
make
make install
#mhash
cd ${SRCDIR}/${MHASH}
./configure --prefix=${INSTALLDIR}
# make clean
make
make install
#freetype
cd ${SRCDIR}/${FREETYPE}
./configure --prefix=${INSTALLDIR}
# make clean
make
make install
#libidn
cd ${SRCDIR}/${LIBIDN}
./configure --with-iconv-prefix=${INSTALLDIR} --prefix=${INSTALLDIR}
# make clean
make
make install
#cURL
cd ${SRCDIR}/${CURL}
./configure --with-ssl=${INSTALLDIR} --with-zlib=${INSTALLDIR} \
--with-libidn=${INSTALLDIR} --enable-ipv6 --enable-cookies \
--enable-crypto-auth --prefix=${INSTALLDIR}
# make clean
make
make install
# c-client
cd ${SRCDIR}/${CCLIENT_DIR}
make ldb
# Install targets are for wusses!
cp c-client/c-client.a ${INSTALLDIR}/lib/libc-client.a
cp c-client/*.h ${INSTALLDIR}/include
#ming
cd ${SRCDIR}/${MING}
./configure --with-ming-prefix=${INSTALLDIR} --prefix=${INSTALLDIR}
# make clean
make
make install
#PHP 5
cd ${SRCDIR}/${PHP5}
./configure ${PHPFEATURES}
# make clean
make
make install
#copy config file
mkdir -p ${INSTALLDIR}/etc/php5/${DOMAIN}
cp ${SRCDIR}/${PHP5}/php.ini-dist ${INSTALLDIR}/etc/php5/${DOMAIN}/php.ini
#copy PHP CGI
mkdir -p ${HOME}/${DOMAIN}/cgi-bin
chmod 0755 ${HOME}/${DOMAIN}/cgi-bin
cp ${INSTALLDIR}/bin/php-cgi ${HOME}/${DOMAIN}/cgi-bin/php.cgi
rm -rf $SRCDIR $DISTDIR
echo ---------- INSTALL COMPLETE! ----------
Leave a Comment