Saturday, September 7, 2013

Learning The MEAN.js stack.

The next few weeks I am going to step out of my comfort zone and mess around and learn Node.js and MongoDB.
I am going to use:

I am going to start here and see what happens.

Tuesday, January 25, 2011

Setting up a Maintenance page with Passenger, nginx and Rails

As simple as it sounds, a maintenance page is something we cannot do without if we want to provide a quality user experience. Googling around has led me to find some solutions, but they violated some of the nginx best practices, particularly the if directive. Many bad things and unexpected behaviors can happen with using in the nginx config.

After some researching and experimentation, I discovered an simple and elegant solution for posting a maintenance page for nginx and Passenger without using ifs and rewrites in the nginx.conf file.

Use something like this in nginx.conf, in the server block:


try_files 
$uri /maintenance.html @passenger;
passenger_enabled on;
root /data/
location @passenger {
  # lolwut? we need this for try_files

  passenger_enabled on;
  root /data/
}


Simply symlink maintenance.html when you need to go offline, and remove it to go back to normal operation.

Saturday, July 24, 2010

Setting up Rails 3 and Ruby-1.9.2-RC2 with RVM on Ubuntu 10.04 Lucid Lynx

Update: Ruby 1.9.2 and Rails 3 have been released, use this instead for Rails 3 and Ruby 1.9.2
#Rails 3
rvm gem install rails
#ruby 1.9.2
sudo rvm --default ruby-1.9.2

With Rails 3 in Beta 4 and the RC coming soon, I wanted to get up to speed with what's new in Rails. Using a VM was the best option, as I didn't want to even try building Ruby again on Windows, with Ruby 1.9.2 being the best option for Rails 3.

Continuing from the VMware install in the last post, we will now install Rails 3.

# dependencies for ruby, rails 3 and rvm install script
sudo apt-get install curl bison build-essential autoconf zlib1g-dev libssl-dev
libxml2-dev libreadline6-dev git-core subversion libsqlite3-dev

Next, install rvm: http://rvm.beginrescueend.com/rvm/install/
This is the system-wide install I will be using: http://rvm.beginrescueend.com/deployment/system-wide/

# run the preconfigured script
sudo bash < <( curl -L http://bit.ly/rvm-install-system-wide )

# Wait for that to build.

# Add to profile to load the rvm path
echo "source '/usr/local/lib/rvm'" >> .bashrc

# Install Ruby
# `rvm list known` for other versions of ruby. ruby-1.9.2-head gave me a compile error.
sudo rvm install ruby-1.9.2-rc2

# Configure default ruby version
sudo rvm --default ruby-1.9.2-rc2

# test ruby install
ruby -v

# Install Rails 3
sudo rvm gem install rails --pre
sudo rvm gem install bundler
sudo rvm gem install sqlite3-ruby

# generate your app
rails appname
cd appname
# run the server!
rails server

Awesome!

If you want to run mongrel with ruby 1.9.2, install the prerelease of mongrel. However mongrel_rails seems broke, at the time of this writing.
sudo rvm gem install mongrel --pre
Unicorn is pretty neat too. It is super fast!
sudo rvm gem install unicorn
# in rails root
unicorn_rails

Friday, July 23, 2010

Installing Ubuntu 10.04 Lucid Lynx on VMware

UPDATE 8/24/10:
If you want to map your VM to an external IP or a domain name, you may need to use VMware Workstation or something with the VMware NAT feature instead of VMware player. On Windows 7/Vista, you might have to disable your firewall for the VMware NAT to work.

Working on a Windows environment can be tricky sometimes with ruby and rails. Expecially if you want to try Rails 3, which recommends using Ruby 1.9.2. So my alternative was to run a VMware instance of Ubuntu.

First off, download the disk image.
http://www.ubuntu.com/desktop/get-ubuntu/download
The 32-bit version should suffice.

When you are done installing Ubuntu on the VM, you may notice the keyboard does not work.
This is because the keyboard settings with the VMware aren't properly configured.

Turn on the on-screen keyboard in the Universal Access Preferences pane.

Reboot the VM and login with the onscreen keyboard. (For me, the on screen keyboard did not appear after the settings change)

A posting on the VMware forums has the fix after you can login:
http://communities.vmware.com/message/1515622#151562

Edit /etc/default/console-setup
vi /etc/default/console-setup

And replace:
XKBMODEL="SKIP"
XKBLAYOUT="us"
XKBVARIANT="U.S. English"
XKBOPTIONS=""

with:
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""

And that should be it!

Wednesday, July 7, 2010

Configuring OAuth2 gem with SSL Peer Certificates

OAuth2 recently has been gaining traction with major social networking sites, such as Twitter and Facebook. The OAuth2 gem makes it easy to access OAuth2 services, such as Facebook.

However if we want to build a user authentication alternative for our own webservices through OAuth, it is important to verify the authenticity of the OAuth provider. We will use HTTPS/SSL since Facebook provides that.

Michael Bleigh has posted this helpful example for Rails 2.3:http://wiki.github.com/intridea/oauth2/rails-23-webserver-example

Using the example alone will give you this warning:

warning: peer certificate won't be verified in this SSL session

This is fine if you are only polling data, but I needed to verify the provider. After some looking around the OAuth gem and Faraday, I found the site parameter, if given a hash, is treated as the options hash.

Download the certificate authority file from: http://curl.haxx.se/ca/cacert.pem and place it somewhere appropriate.

Using the example modify the client method to:
def client
ca_file = File.join('ca_file_path')
@client ||= OAuth2::Client.new(
'appid', 'app_secret',
{
# Faraday treats the site param if it is a hash as the options hash
:site => {
:url=>'https://graph.facebook.com',
:ssl=>{
:verify=>OpenSSL::SSL::VERIFY_PEER,
:ca_file =>ca_file
}
},
# doesnt have to be NetHttp
:adapter => :NetHttp}
)
end
And that should work!