CREATE TABLE congress_members (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(64) NOT NULL,
party VARCHAR(64) NOT NULL,
location VARCHAR(64) NOT NULL,
grade_1996 REAL,
grade_current REAL,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quicksort(array, from=0, to=nil) | |
if to == nil | |
# Sort the whole array, by default | |
to = array.count - 1 | |
end | |
if from >= to | |
# Done sorting | |
return | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To understand recursion, you first need to understand recursion. | |
# Now, on a serious note, | |
# a recursive function is one that calls itself. | |
# For a recursive algorithm to terminate you need a base case | |
# (e.g. a condition where the function does not call itself recursively) | |
# and you also need to make sure that you get closer to that base case in each recursive call. | |
# Let's look at a very simple example first: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hospital | |
attr_accessor :name, :address, :employees, :patients | |
def initialize(args) | |
@name = args[:name] | |
@address = args[:address] | |
@employees = args[:employees] || [] | |
@patients = args[:patients] || [] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------- | |
# variable scope: understanding where a variable "lives" | |
# -------------------------------------------------------- | |
# | |
# in Ruby there are: | |
# - 4 kinds of variable scope: | |
# | |
# - global ($db, $connection, $file) | |
# - class (@@total, @@poolsize) | |
# - instance (@age, @name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Github | |
class Client | |
include HTTParty | |
base_uri "https://api.github.com" | |
def initialize(username, password) | |
@user_auth = { :username => username, :password => password } | |
@token_auth = "token 8205ba1597bdb27b197018ea35117d1ef45e588f" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint strict: false */ | |
/*global $:false, undef: true */ | |
/*jshint unused: false, undef:false */ | |
$(document).ready(function(){ | |
//Model | |
var Die = function (id) { | |
this.side = 0; | |
this.id = id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
var controller = new Controller; | |
$('#roller button.add').on('click', function() { | |
controller.add(); | |
}); | |
$('#roller button.roll').on('click', function() { | |
controller.roll(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
var controller = new Controller; | |
$('#roller button.add').on('click', function() { | |
controller.add(); | |
}); | |
$('#roller button.roll').on('click', function() { | |
controller.roll(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
// Die model | |
var Die = function(id) { | |
this.value = Math.floor((Math.random()*6)+1); | |
this.id = id; | |
} | |
Die.prototype.roll = function() { |