Installing FreeImage on Mac OS X Lion

I think you all know that I don’t like Macport nor Homebrew as I prefer to compile everything. I also don’t like the fact that ImageScience requires FreeImage. Well, in order to compile and install FreeImage, you have to go modify Makefile.osx. Below is the content and here’s the link to the gist.

This is for Lion since it’s all 64-bit and the SDK is 10.7. You don’t have to worry about the latest Xcode. Just make and sudo make install. That’s all!

Starting a Project without IB

Who’s Calling Me?

This is really bad, but here might be a situation where you’ll have to handle a method differently depending on method it’s being called from. Here’s a demo of how you can identify the name of the caller.

Watchr Script That Works

Deploying Rails 3 App – Step 1, Server Preparation

I use only LTS version of Ubuntu, so it’s Ubuntu 10.04 at this time. No, I don’t use RVM in production, it’s just my own personal preference.

1) Server Basics
sudo apt-get install build-essential bison openssl libreadline-dev zlib1g-dev libssl-dev libncurses5-dev ruby wget curl subversion

2) Install Ruby
svn export http://svn.ruby-lang.org/repos/ruby/tags/v1_9_2_0/ ruby
cd ruby
autoconf
./configure –prefix=/usr –enable-pthread
make
sudo make install

3) Install Git
wget http://kernel.org/pub/software/scm/git/git-1.7.3.1.tar.bz2
tar xvjf git-1.7.3.1.tar.bz2
cd git-1.7.3.1
./configure –prefix=/usr/local –without-tcltk
make
sudo make install

4) Install Bundler
sudo gem install bundler passenger

5) Install Nginx & Passenger
sudo passenger-install-nginx-module

After this, create a deploy account and generate ssh key for Git repository.

Next, capifying the app!

API Tips – Removing HTML From String in Model/Controller

strip_tags method really comes in handy when you have to render out a string in DB. However, what if you have to return that from a controller or a model, which is often the case when you’re developing an API.

In Rails, here’s a simple way to do it.


> HTML::FullSanitizer.new.sanitize("<b>Hope</b> <a href='whatever'>my link</a>")
=> "Hope my link"

Squashing Multiple Commits In Git

Here’s how I create a patch that squashes multiple commits into one, making it easier for the maintainer to review in a project or if you’re working with SVN repo.

Assumptions:

  • The work is done at “working” branch.
  • You’re merging in your changes to “master”
  • “tmp” branch will be used to create the patch
  • The patch will be placed in your Desktop (remember, I use Mac)

Steps:

  • from “master”,
    git checkout -b tmp
  • fetch the squashed commit.
    git merge --squash working
  • commit the differences.
    git commit -a -m "your commit comment"
  • create the patch.
    git format-patch -o ~/Desktop/ master
  • apply patch and clean up.
    git checkout master
    git am ~/Desktop/{name of the patch}
    git branch -D tmp

At this point, you may also want to remove working branch and create a fresh branch.

Installing Redis on Mac Snow Leopard

Here’s how I do it.

Step 1 – Get the source and compile it

Step 2 – Place the binaries and configure

  • copy redis-benchmark, redis-server, redis-cli, and redis-stat to /usr/local/bin and set the owner to root.
  • copy redis.conf to /usr/local/etc and change “daemonize” to “yes”
  • if you want it to start when the system boots, create redis.plist in ~/Library/LaunchAgents directory with following content:

    Then use the following command to automatically start when your computer boots:

Step 3 – Test

  • open Redis CLI by entering “redis-cli”
  • open Redis CLI again

Resetting Mock

Replace “mocked” with your mocked object.

Quick Markdown to HTML Conversion Script

Using BlueCloth gem.

To run:

  ruby {file_name}.rb {input_file} {output_file}

Powered by Olark