Skip to content

Instantly share code, notes, and snippets.

View bootcoder's full-sized avatar

Hunter Chapman bootcoder

View GitHub Profile
@bootcoder
bootcoder / quick_sort.rb
Created October 21, 2015 23:36
Sample of Quick sort
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
@bootcoder
bootcoder / 3.1_sql_congress_db_ANSWERS.md
Last active September 21, 2015 21:57
congress_db_answers.md

Build Schema

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,
@bootcoder
bootcoder / 1.3-Recursion.rb
Created September 9, 2015 22:14
recursion_breakout.rb
# 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:
class Hospital
attr_accessor :name, :address, :employees, :patients
def initialize(args)
@name = args[:name]
@address = args[:address]
@employees = args[:employees] || []
@patients = args[:patients] || []
end
# --------------------------------------------------------
# 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)
@bootcoder
bootcoder / Github_HTTParty_demo.rb
Last active August 29, 2015 14:23
Demo to show off some HTTParty methods interacting with the Github API
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"
/*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;
$(document).ready(function() {
var controller = new Controller;
$('#roller button.add').on('click', function() {
controller.add();
});
$('#roller button.roll').on('click', function() {
controller.roll();
});
});
$(document).ready(function() {
var controller = new Controller;
$('#roller button.add').on('click', function() {
controller.add();
});
$('#roller button.roll').on('click', function() {
controller.roll();
});
});
$(document).ready(function() {
// Die model
var Die = function(id) {
this.value = Math.floor((Math.random()*6)+1);
this.id = id;
}
Die.prototype.roll = function() {