Backbone.js and jQuery dataTables

Posted in backbone, dataTables, javascript, jquery | Leave a comment

Scoring Ruby Koan Answer

This is my answer for the about_scoring_project ruby koan.

I would love feedback, comment below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Greed is a dice game where you roll up to five dice to accumulate
# points.  The following "score" function will be used calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
# * A set of three numbers (other than ones) is worth 100 times the
#   number. (e.g. three fives is 500 points).
#
# * A one (that is not part of a set of three) is worth 100 points.
#
# * A five (that is not part of a set of three) is worth 50 points.
#
# * Everything else is worth 0 points.
#
#
# Examples:
#
# score([1,1,1,5,1]) => 1150 points
# score([2,3,4,6,2]) => 0 points
# score([3,4,5,3,3]) => 350 points
# score([1,5,1,2,4]) => 250 points
#
# More scoring examples are given in the tests below:
#
# Your goal is to write the score method.

def score(dice)
  # You need to write this method
  total = 0
  counter = {}
  dice.each do |num|
    counter[num] ? counter[num] += 1 : counter[num] = 1
  end
  counter.each do |key, value|
    if value >= 3
      total += key == 1 ? key * 1000 : key * 100
      value -= 3
    end
    if key == 1
      total += value * 100
    elsif key == 5
      total += value * 50
    end
  end
  total
end
Posted in Ruby, RubyKoans | 1 Comment

Setting up EC2 Instance for rails 3.1 – Getting Started / Server Setup

Getting started…..

So I am getting ready to launch a Rails 3.1 application, that needs to go beyond the typical Heroku hosting solution. Specifically, I need some libraries install and accessible to my gems from my app. This just isn’t possible with Heroku, so I started looking for the solution. I thought about building a server, co-location, etc… and finally decided based on cost and ease of scalability that I would go with Amazons Web Services. So I set out to figure out how to do that.

Chef, in my impression gives you an excellent way to easily deploy servers, either on your own network or in the cloud. So I started there.

I learned very quickly that Deploying a server was the easy part, having it automatically configured seems to be a bit more tricky and I hope to get my self to the point of having my own cookbooks and recipes set up. But for now I am just going to use chef to create my instance on Amazon’s AWS EC2.

I started by checking out and reading through some of the chef documentation, and getting started guides, then moved on to this extremely helpful article http://www.agileweboperations.com/amazon-ec2-instances-with-opscode-chef-using-knife

1 micro instance on the cloud is free, so I’m going to get started with that:

Setting up micro instance

1
2
3
$ knife ec2 server create -I ami-ab36fbc2 -f t1.micro -S knife -i ~/.ssh/knife.pem --ssh-user ubuntu --region us-east-1
$ ssh to-my-new-ec2-instance
ubuntu@my-new-server$

Server Setup…

First I need to document my server setup, so that later I can use this setup to start building chef recipes and cookbooks.

postgres db server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
ubuntu$ sudo apt-get update
ubuntu$ sudo apt-get install postgresql postgresql-contrib libpq-dev
ubuntu$ sudo su
root$ su -u postgres psql postgres
#set the postgres users db password
\password postgres
\q

# create the db user and db for my rails 3.1 application
root$ su postgres
postgres$ createuser ubuntu
postgres$ exit
root$ exit
ubuntu$ createdb -U ubuntu name-of-my-apps-database

Get more packages and setup RVM….. (server setup cont.)

1
2
3
4
5
6
7
ubuntu$ sudo apt-get install build-essential zlib1g-dev curl git-core sqlite3 libsqlite3-dev

# rvm installation
ubuntu$ bash < ubuntu$ source .bashrc

#application specific packages
ubuntu$ sudo apt-get install xvfb firefox
Posted in Rails, Ruby on Rails | Tagged , , | Leave a comment

Setting up a Brand New Mac Book Pro for Development


First thing, Install homebrew

Installation instructions can be found here:

https://github.com/mxcl/homebrew/wiki/installation

Then following the final recommendation by Homebrew, I purchased Xcode4 for $4.99.
While waiting for the 4.56GB Xcode4 to download, I figured I might as well do some other easy tasks.

  • Dropbox – http://www.dropbox.com/ – Quic Download and Install….
  • RubyMine – http://www.jetbrains.com/ruby/ – Ruby and Rails IDE with the full stack of essential developer tools, all tightly integrated into a convenient
    and smart development environment.

Ahhh Xcode4 finished Downloading.. Now Run The Install

Next, Cinderella – https://github.com/atmos/cinderella

What It Gives You

  • mysql, postgres, redis, solr, memcached and mongodb
  • ruby (1.8.7) with rails and sinatra via rvm gemsets.
  • python (2.7) with pip.
  • node.js (0.2.0) with npm.
  • erlang (R13B04) environment.

This may take a while — Go Tubing down the Minnehaha Creek

Finished…

1
ln -s Developer/.rvm/ .rvm

Start RubyMine and import settings from the settings.jar file you have saved in your dropbox next to your rails projects ;-)

MacPorts

ImageMagick

Posted in Oracle 10g R2 | Oracle 11g | Leave a comment

401 Unauthorized coming from Delayed::Job.enqueue

Delayed::Job.enqueue(FileUpload.new(28))
RestClient::Request::Unauthorized: 401 Unauthorized
/app/.bundle/gems/ruby/1.8/gems/rest-client-1.6.1/lib/restclient/abstract_response.rb:48:in `return!’
/app/.bundle/gems/ruby/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb:220:in `process_result’
/app/.bundle/gems/ruby/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb:169:in `transmit’
/usr/ruby1.8.7/lib/ruby/1.8/net/http.rb:543:in `start’

Heroku logs running app
2011-06-29T21:25:31+00:00 app[web.1]: RestClient::Request::Unauthorized (401 Unauthorized):

I recently ran into an issue of using Delayed_Job on Heroku were I was receiving a 401 Unauthorized Error. The issue was caused by the use of the workless gem that scales workers on your Delayed Job Processes. When I moved the application from my account to the clients account I did not change the Heroku config variables and since I was no longer an owner on the application, my credentials did not have the authorization to scale workers.

the Fix:

Add your Heroku username / password as config vars to your Heroku instance, the same one you log in to Heroku with (the Application Owners Credentials)

heroku config:add HEROKU_USER= HEROKU_PASSWORD=

Hope this Helps

Posted in Ruby on Rails | Tagged , , , , , | Leave a comment