Skip to content

Instantly share code, notes, and snippets.

Current as at 25-Feb-2014

#Ruby Notes ###Terminology Literals = values e.g. 1 or "Simon"
Variables = a place to store values
Operator = + - * / % = Parameter = inputs for variables
Fix_num = an integer

print "enter loan amount: "
loan = gets.chomp.to_i
print "Enter length of time in months: "
time = gets.chomp.to_i
print "Enter interest rate: "
rate = gets.chomp.to_f/100
i = (1+rate/12)**(12/12)-1
annuity = (1-(1/(1+i))**time)/i

Robot Name

When robots come off the factory floor, they have no name.

The first time you boot them up, a random name is generated, such as RX837 or BC811.

In other words, if I say:

puts "Robot 1: "
##Dependencies
#If you want to require library c when you install it it requires library d;
#Things you are depending on depend on other things;
##PACKAGE MANAGER SOLVES ALL OF THIS!
gem install package name #Will work out where to store it on your system, it will work out all the dependencies and go and download them;
#Some gems are very complicated such as ImageMagick, it depends on software that is written on your computer and not in ruby;
require 'sinatra' #only works if we have installed sinatra on our machine;
##DEPLOYING TO HEROKU
#Create an account on Heroku
https://www.heroku.com
#Download Heroku Toolbelt (a client for generating and creating heroku apps);
https://toolbelt.heroku.com/
heroku login #in the command line #It should generate SSH keys (we may have to do this manually);
#Gem list and check that you have the gem bundler; (You can do gem list | grep bundler);
#If you do not have it then install it:
gem install bundler #We have already done this;

Current as at 18-MAR-2014

###HTTP Requests###

Contains… GET

  • domain
  • path

###Controller

Current as at 18-MAR-2014

#Rails Notes


###HTTP Requests###

Contains… GET

  • domain

PAPER - work out what form all of your data will take- tables and field names

TERMINAL - rails new NAME -d postgresql

TERMINAL - cd into that NAME folder and subl .

SUBL - open your gemfile and add all the extra gems you want

TERMINAL - bundle

Sublime Text 2 - Useful Shortcuts

Tested in Mac OS X: super == command

Open/Goto


  • super+t: go to file
  • super+ctrl+p: go to project
  • super+r: go to methods