Skip to content

Instantly share code, notes, and snippets.

@ichabodcole
ichabodcole / gist:4749379
Last active December 12, 2015 09:09
Portland Code School Blog: Week 1
First week of Portland Code School: lessons learned.
<ul id=”random-thoughts”>
There are only so many hours in the day, pick your battles and make sure
have something interesting to ask or bring up for the next day's class.
Specifically, DO YOUR HOMEWORK, it will pay off in class when you can actually
put the teacher to use. A schedule and notes will help with all of the above.
Don’t just voice your questions, voice them so everyone can hear them.
It’s really important to over-communicate in a classroom.
@ichabodcole
ichabodcole / gist:4991398
Created February 19, 2013 23:53
Simple rack file loader.
class FileLoadingApp
def call(env)
m = nil
headers = {'content-type'=>'text/html'}
r = Rack::Request.new(env)
path = r.path.slice(1, r.path.size)
puts path
File.open(path, 'rt') do |f|
m = [200, headers, [f.read]]
puts m
@ichabodcole
ichabodcole / gist:5206677
Created March 20, 2013 17:35
Scrabble Tests
class Scrabble
# Note I cheated to get the values hash right,
# but cool thing is you can use integers as key values,
# which comes in handy below.
VALUES = {
1 => %w{a e i o u l n r s t},
2 => %w{d g},
3 => %w{b c m p},
4 => %w{f h v w y},
5 => %w{k},
@ichabodcole
ichabodcole / gist:5206684
Created March 20, 2013 17:35
Scrabble Code
require 'minitest/spec'
require 'minitest/autorun'
require './scrabble.rb'
describe Scrabble do
describe "word_score" do
it "should return 14 if word is Cabbage" do
Scrabble.word_score("Cabbage").must_equal 14
end
@ichabodcole
ichabodcole / gist:5209060
Created March 20, 2013 22:19
Deaf Grandma
class Grandma
def initialize
@message = "";
end
def speak_to(message)
if message == "BYE"
good_bye
return true
end
@ichabodcole
ichabodcole / robot_name.rb
Created March 25, 2013 21:53
Robot Name Warm-up
class Robot
def initialize
@count = 0;
@name = generate_name
@mac = generate_name + ":" + generate_name
@created_at = Time.now
@reset_at = 0
end
def generate_name
@ichabodcole
ichabodcole / Web Audio API - Sound Fading
Created July 3, 2013 18:40
Reference for fading in and out sounds with the Web Audio API
fadeTo: (value, fadeLength)->
fadeLength = fadeLength || @defaultfadeLength
currentTime = @ctx.currentTime
#time the fade should complete
fadeTime = currentTime + fadeLength
#set the start time
@masterGain.gain.setValueAtTime(@userVolume, currentTime)
@masterGain.gain.linearRampToValueAtTime(value, fadeTime)
fadeOut: (fadeLength)->
/*! Js Pub/Sub
* http://anasnakawa.com/
* Copyright (c) Anas Nakawa
* inspired by Ben Alman's one <https://gist.github.com/cowboy/661855>
* MIT License
*/
(function( p ) {
var e = p.e = {};
@ichabodcole
ichabodcole / gist:c7c6a2007d18c94377ba
Created December 17, 2014 06:58
jasmine 2.1 - CustomMatcher -- toBeNearTo
jasmine.addMatchers({
toBeNearTo: function (utils, customEqualityTesters) {
return {
compare: function(actual, expected, within) {
var diff,
result = {};
within = Math.abs(within) || 1;
diff = Math.abs(actual - expected);
result.pass = diff <= within;
@ichabodcole
ichabodcole / index.js
Created July 4, 2015 20:42
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
'use strict';
//var global = require('global');
//var document = require('global/document');
var immstruct = require('immstruct');
var hg = require('mercury');
var h = hg.h;
var ctx = new AudioContext();