Friday, January 23, 2009

Speeding up emailing in tests

I lived with the fact that my test ground to a halt when my tests ran code that had to send emails. It finally got so bad I started asking around about it.

I knew about a method to test ActionMailer and not send out emails... and I thought: why not apply these to ActionMailer when it's in the test environment? I ran my tests with rspec. Check out the pastie to see the code.

Tuesday, October 21, 2008

RSpec, attachment_fu

I've been looking for a solution to force RSpec tests to override the attachment_fu storage setting. Since I use s3, it was very inefficient when I'd run my tests because the assets would be saved in s3. Not only does it cost money, but it was very slow.

After spamming #rubyonrails I finally got an answer from _martinS_. He told me to do something like this: http://pastie.org/296895 - and it worked! I hope this helps you guys.

Sunday, September 28, 2008

Compiling Sphinx in Ubuntu

I had just watched Ryan Bates' screencast on Sphinx and I wanted to install it on Ubuntu. Took me a while to find out how, so here are my instructions. I'm on Ubuntu 8.04

1. Download the latest realease. It's 0.9.8 as of writing.
2. Install it with their instructions. I ran into a problem though - I have MySQL already but not the files Sphinx needs to install. If you ran into this problem, continue:
3. In console, type:

mysql_config --cflags

That will tell you the package you need to install.
4. Mine was libmysqlclient15-dev:

sudo apt-get install libmysqlclient15-dev

5. Try installing Sphinx again, it should work this time.

Tuesday, September 9, 2008

attachment_fu, Rails 2.1 and before_thumbnail_saved

I was working on before_thumbnail_saved callback in Rails 2.1 and it seems it has changed! It didn't work with me anymore. At least my old code didn't.

Apparently, you only pass the thumbnail into the loop.

Read this blog post for details.

Friday, September 5, 2008

Rake: Update or create images generated by attachment_fu

Did you upload a bunch of images and find out that the new layout needs a new size of the photos, and you didn't specify this in the has_attachment line of your model?

This happened to me, and I wanted an easy to way update all images in the database. I didn't test this with millions of records or anything, but if you want to fix this up please leave a comment.

Notes:
  • To use, simply edit has_attachment line with the new thumbnail sizes you want.
  • IdeaImage is the model that I want to update
  • parentless is a named_scope that gets only the IdeaImages whose parent_id's are null.

namespace :images do
desc "Updates all the thumbnails of idea_images based on the thumbnails hash in the model"
task(:update_idea_images => :environment) do
IdeaImage.parentless.each do |i|
#destroy the thumbnails first
i.thumbnails.each { |thumbnail| thumbnail.destroy } if i.thumbnailable?
#then recreate the thumbnails
i.attachment_options[:thumbnails].each { |suffix, size| i.create_or_update_thumbnail(i.create_temp_file, suffix, *size) }
end
end
end

Friday, August 1, 2008

Installing the latest gVim and Vim in Ubuntu Hardy Heron

I recently got a new computer and reinstalled Ubuntu and found out that my old post on how to install the latest gVim in Hardy Heron didn't work anymore. This is what I did to install the latest one. Thanks godlygeek!


sudo apt-get build-dep vim
sudo apt-get install build-essential devscripts fakeroot dpkg-dev
apt-get source vim
cd vim-7.1
(cd upstream/patches; python get_patches.py)
dch -v 1:7.1-138+1ubuntu4~$(whoami)1 "Updated with patches through $(ls upstream/patches | grep -v '\.py$' | tail -n 1)"
sed -i -e '/gvimtutor/d' -e "1idebian/tmp/usr/bin/gvimtutor\t\t\t\tusr/bin/" debian/vim-runtime.install.in
dpkg-buildpackage -rfakeroot -uc -b
Having trouble viewing that? See the pastie.

Now, you're supposed to have .deb files in the parent directory. I ran into a problem though in the last line. Here are the last few lines of output after running dpkg-buildpackage -rfakeroot -uc -b: http://pastie.org/246789

To fix this, godlygeek asked me to edit vim-7.1/debian/vim-runtime.install.in and remove the line with gvimtutor in it. See my vim-runtime.install.in file.

So I edited it (gedit
vim-7.1/debian/vim-runtime.install.in), then ran the last line (
dpkg-buildpackage -rfakeroot -uc -b
in vim-7.1 directory again.

I got the compiled *.deb files in the parent directory!

To install them (note that your files will look different):

sudo dpkg -i vim-full_7.1-138+1ubuntu4~ramon1_all.deb
sudo dpkg -i vim-gui-common_7.1-138+1ubuntu4~ramon1_all.deb
sudo dpkg -i vim-runtime_7.1-138+1ubuntu4~ramon1_all.deb
sudo dpkg -i vim-gnome_7.1-138+1ubuntu4~ramon1_i386.deb

Sunday, July 27, 2008

gVim and placing scripts

It seems that everytime I install gVim in Ubuntu the place to put scripts is different. If anyone can shed some light on this please let me know. The last time I installed it, I put the scripts in /usr/share/vim/vimcurrent