Coffeescript: Fat arrow vs thin arrow

In any JavaScript function, the value of this is the object that the function is attached to. However, when you pass functions to other functions or reattach a function to another object, the value of this will change. Sometimes this is what you want, but often you would like to keep the original value of this.

For this purpose, CoffeeScript provides the =>, or fat arrow, which will define a function but at the same time capture the value of this, so that the function can be safely called in any context. This is especially useful when using callbacks, for instance in a jQuery event handler.

Read More »

omniauth-facebook + rails 3 + authlogic debug

Personally I prefer Devise to Authlogic but recently I have to work with Authlogic on a legacy codebase. But I still like Devise because it’s up-to-date, clean, easier to use…

omniauth-facebook provides a cool way to login with FB – display a popup instead of redirecting users to FB login page then back to our site. Obviously this is the way we want :)

We won’t re-invent the wheel here, let’s follow Railcasts #360 to have omniauth-facebook integrated to your app. These are some issues you may encounter:

Read More »

Rails + oauth-plugin + mongodb – Part 2: Consumer

In previous post, we went through the process to create a Provider with Oauth-plugin that works with Mongodb using mongid as the driver. Here we will build the Consumer using mongoid too.

This Consumer app will run on port 4000 (rails s -p 4000) and connect with the Provider app which will be running on port 3000.

Step 1 – step 3

Exactly the same as in previous post for Provider

Read More »

Rails + oauth-plugin + mongodb – Part 1: Provider

Recently I had a chance to work with Oauth and Rails using oauth-plugin and mongodb. Although oauth-plugin itself has a documentation but actually doesn’t cover the mongoid part detailed enough. Also I found this very good tutorial but it’s for SQLite3 only: Oauth Provider, Oauth Consumer

Base on the above posts, to get Rails and oauth-plugin working with mongodb, you need to do some changes.

Firstly, create a oauth-sample directory, you’ll put provider and consumer apps in there.

Read More »

BrowserCMS: from development to production

There’re some Rails CMS such as Radiant, Refinery, BrowserCMS… and I find BrowserCMS the best one to build simple websites for my customers, we can easily create dynamic content for you websites with Portlet, create new object to manage by with Content type, and easily create template for each page (homepage, subpages…).

In this post we won’t talk about how to use BrowserCMS, please go to the BrowserCMS Wiki if you’re finding that information. This post just concentrates on things you need to do to get BrowserCMS work properly on server in production mode.

Read More »

Mac OS: Lock screen with keyboard shortcut

When I step away from my Mac at work, I want a quick way to lock the screen, and hitting a hot-corner with the mouse is problematic for me. This hint details how to lock the screen from the keyboard by using Automator to build a Service in Snow Leopard.

First, check the General tab on the Security System Preferences panel to ensure that the Require password [some period] after sleep or screen saver begins box is checked.

Read More »

Install MongoDB on Snow Leopard

I have to install MongoDB on a Linode server with Ubuntu 10.04. So I decided to install it on my MBP first. It’s a cool little database, and John Nunemaker’s MongoMapper gem is a treat.

Here’s how I got the server installed and running as a daemon in Snow Leopard for local development.

Download, unpack, and install the pre-compiled 32-bit binaries:

curl -O http://downloads.mongodb.org/osx/mongodb-osx-i386-1.4.0.tgz
tar xzf mongodb-osx-i386-1.4.0.tgz
sudo mv mongodb-osx-i386-1.4.0 /usr/local/mongodb
sudo mkdir /usr/local/mongodb_data /var/log/mongodb
sudo chown -R root /usr/local/mongodb

(If you’re on a 64-bit machine, substitute in x86_64 for each i386 above.)

Read More »