Skip to content

Instantly share code, notes, and snippets.

@maker-leo
maker-leo / Sublime-Text.markdown
Last active December 14, 2015 19:19 — forked from leoallen85/Sublime-Text.markdown
A guide to getting the most out of your new favourite editor Sublime Text

Sublime Text 2

Although you're free to use any editor we recommend Sublime. Here's how to get the most out of it

Setting up

Once you've installed Sublime there's a few things you should do to get things set up properly:

Package Control

@maker-leo
maker-leo / Ruby.sublime-build
Created March 11, 2013 16:53 — forked from leoallen85/Ruby.sublime-build
Go to Sublime Text 2 > Preferences > Browse Packages... to open finder, then open the Ruby.sublime-build file in the Ruby folder and replace the contents with this to get the Build command (cmd + B) working with RVM
{
"env":{
"PATH":"${HOME}/.rvm/bin:${PATH}"
},
"cmd": ["rvm-auto-ruby", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}
@maker-leo
maker-leo / Preferences.sublime-settings
Last active December 14, 2015 19:19 — forked from leoallen85/Preferences.sublime-settings
Suggested settings for your Preferences.sublime-settings.
{
// This is the ruby default
"tab_size": 2,
// Set to true to insert spaces when tab is pressed
"translate_tabs_to_spaces": true,
// This shows all your whitespace, including spaces and tabs
// helps keep code clean and properly indented!
"draw_white_space": "all",
@maker-leo
maker-leo / Ruby-universe.md
Created March 12, 2013 16:37
All the different parts of the Ruby universe

The Ruby universe

This is a brief introduction into the world of web development and Ruby. To view all the different gems listed by popularity check out the Ruby Toolbox.

Web frameworks

  • Rails - the most popular, although recently has been criticised for being a bit bloated - giving you more than you often need to build a simple web site
  • Sinatra - takes the opposite principal, more of a "micro framework" that starts with just enough to get you going, and you can then add Gems for more advanced stuff as and when you need it

Models

@maker-leo
maker-leo / ruby-intro.rb
Created March 19, 2013 12:17
All the examples from our introduction to Ruby
def vader(evil = false)
# guard clause
return "something else" if evil == "luke"
# implicit return, last line executed
if evil
"i am your father and I hate you"
else
"i am your father and i love you"
end
@maker-leo
maker-leo / arrays.rb
Created March 19, 2013 16:08
Some example of array methods in Ruby
# You can loop through a range
(1..10).each {|a| puts a }
first_ten = (1..10).to_a
# You can convert it into an array
puts first_ten.inspect
puts "selecting odd numbers"
@maker-leo
maker-leo / blocks.rb
Created March 19, 2013 16:10
Some examples of blocks, including our own implementation of select
def do_some_maths
puts yield(10)
puts yield(20)
end
do_some_maths do |num|
num * 20
end
do_some_maths do |number|
@maker-leo
maker-leo / ruby-exercises.rb
Created March 19, 2013 17:35
Here's some exercises to go over tonight
#create your own methods
#create a method with one argument, and print it out
#create a method with two arguments
#create a method with one argument, which by default is nil
#create a method that returns two values, depending on if an argument is true or false
#take this hash, and use it to make this string. Make sure you use the hash twice,
#and use string interpolation i.e. "A string #{variable}"
hash = {:dario => "Dario", :leo => "Leo"}
@maker-leo
maker-leo / gist:5253814
Created March 27, 2013 12:29
Setting up your computer
- Copy setup.zip to your Downloads folder
- Double click the folder to unzip the folder
- Open the folder, and then once inside:
@maker-leo
maker-leo / dice_test.rb
Created March 27, 2013 17:08
Example of mocking in Ruby to take away our dependency on randomness. Don't forget to add mocha to your Gemfil
require 'minitest/autorun'
require 'mocha/setup'
require './lib/dice'
class DiceTest < MiniTest::Unit::TestCase
def setup
@one_dice = Dice.new(1)
@two_dice = Dice.new(2)
end