Hosting a Static Site on an S3 Bucket


I love the recent shift from dynamic sites to static sites. This doesn’t work for all sites. But why have a blog that gets dynamically build on each request. It’s Not needed.

Amazon will host static sites on an S3 bucket and its dead simple. Awesome!

  1. Create a bucket and set as public host.
  2. Upload files and make them public.
  3. Profit.

Migrate a Single Database Migration


1
2
3
rails console
require "db/migrate/20121130134444_add_column_backorder_to_orders.rb"
AddColumnBackorderToOrders.up

Form Helper From Console


From the rails console.

1
2
3
helper.text_field :object, :name

"<input id=\"object_name\" name=\"object[name]\" size=\"30\" type=\"text\" />"

Set Default Value in Rails Model


I like to set default values in my models. This is the method I like to use.

1
2
3
4
5
def after_initialize
  if new_record?
    self.upper_quantity ||= 0.0
  end
end

Failed to Connect to a Master Node at Localhost:27017


Everytime my server looses power, Mongo has trouble restarting. These commands fixes the problem.

1
sudo rm /var/lib/mongodb/mongod.lock
1
2
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb restart

Install Elastic Search on Ubuntu


Update Package Manager

1
sudo apt-get update

Install JRE

1
sudo apt-get install openjdk-7-jre-headless -y

Install Elastic Search

1
2
3
4
5
wget http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.2.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share

Install the Service Wrapper

1
2
3
4
5
6
7
curl -L http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz
sudo mv *servicewrapper*/service /usr/local/share/elasticsearch/bin/
rm -Rf *servicewrapper*
sudo /usr/local/share/elasticsearch/bin/service/elasticsearch install
sudo ln -s `readlink -f /usr/local/share/elasticsearch/bin/service/elasticsearch` /usr/local/bin/elasticsearch
sudo service elasticsearch start
curl http://localhost:9200

Ubuntu Ip-address


1
sudo vim /etc/network/interfaces
1
2
3
4
5
6
7
8
9
10
11
12
13
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.4
netmask 255.255.255.0
gateway 192.168.1.1