Skip to content

Instantly share code, notes, and snippets.

View leoallen85's full-sized avatar

Leo Allen leoallen85

  • Makers Academy
  • London, UK
View GitHub Profile
@leoallen85
leoallen85 / .rdebugrc
Created February 28, 2013 16:19
An example ruby debug settings file, put this in your home directory as ~/.rdebugrc
set autoeval
set autolist
set autoreload
@leoallen85
leoallen85 / class_methods..rb
Created February 28, 2013 16:30
An introduction to class methods in Ruby
class HTML
def initialize(str)
@str = str
end
# instance method (note it makes use of an instance variable)
def render
puts "<div>#{@str}</div>"
end
@leoallen85
leoallen85 / public_and_protected.rb
Created February 28, 2013 16:47
This shows public, private, and protected methods in Ruby. This is a way of controlling which methods can be accessed from outside the object
class Base
def public_method
puts 'public method called'
end
# This works as we are calling the private method
# from within the object
def call_private_method
private_method
@leoallen85
leoallen85 / debugger.rb
Created February 28, 2013 16:49
A simple example just to show you how to set break points using Ruby debug
require 'debugger'
class Hello
def hi_there
debugger
puts "wohoo"
end
end
testing = Hello.new
@leoallen85
leoallen85 / Preferences.sublime-settings
Created March 1, 2013 10:12
Recommended Sublime User settings, you can access your own settings by going Sublime Text 2 > Preferences > Settings - User or pressing ⌘ + , Then add these to your preferences
{
// This means every time you move away from your current tab it saves, no more cmd + s!
"save_on_focus_lost": true,
// Let's get rid of all those trailing white spaces!
"trim_trailing_white_space_on_save": true,
// A good idea to view all white space to make sure you're not using tabs
"draw_white_space": "all",

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

@leoallen85
leoallen85 / Ruby.sublime-build
Created March 11, 2013 16:47
Allows you to run Ruby files from sublime. To fix this, enter in the terminal `subl ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/Ruby.sublime-build` and put this code in your file
{
"env":{
"PATH":"${HOME}/.rvm/bin:${PATH}"
},
"cmd": ["rvm-auto-ruby", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}
require 'rubygems'
def start_simplecov
require 'simplecov'
SimpleCov.start 'rails' unless ENV["SKIP_COV"]
end
def spork?
defined?(Spork) && Spork.using_spork?
end

MySequel

This is an exercise in which you need to use some more advanced SQL skills in order to find out some information about a dataset of famous movie sequels.

The exercise

First of all fork and clone this repository from github.

You will see in /spec/exercises_spec.rb are a number of pending specifications. Get them to pass to complete the exercise.

[
{ "keys": ["Y"], "command": "clipboard_copy",
"context": [{"key": "clipboardcopy_fake", "operator":"equal", "operand":true}, {"key": "setting.command_mode"}]
},
{ "keys": ["y"], "command": "clipboard_copy",
"context": [{"key": "clipboardcopy_fake", "operator":"equal", "operand":true}, {"key": "setting.command_mode"}]
},
{ "keys": ["D"], "command": "clipboard_copy",
"context": [{"key": "clipboardcopy_fake", "operator":"equal", "operand":true}, {"key": "setting.command_mode"}]
},