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
# swap loops so we can exit early from the inner loop once we've searched the valid range | |
require "pp" | |
require "minitest/autorun" | |
class StockTest < Minitest::Test | |
attr_accessor :loops | |
def pick_best_time_to_buy(stock) | |
best_value = 0 |
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
function lazyCompileFactory(id, html) { | |
crunch.global.templates[id] = function(context) { | |
var compiled = Handlebars.compile(html); | |
crunch.global.templates[id] = compiled; | |
return compiled(context); | |
} | |
} | |
$('script[type="text/x-handlebars-template"]').each(function() { | |
var text = this.textContent; |
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
#!/usr/bin/env bash | |
apt-get -y update | |
apt-get -y upgrade | |
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev libffi-dev libjemalloc-dev | |
apt-get -y install autoconf curl bzip2 | |
apt-get -y autoremove | |
apt-get -y clean | |
cd /usr/local/src | |
curl http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz |
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 Parser | |
@formats = {} | |
class << self | |
attr_accessor :formats | |
def create(format) | |
formats[format].new | |
end | |
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
# super-meta object persistence class to Redis | |
class RedisObject | |
include ActiveModel::Serialization | |
attr_accessor :attributes, :id | |
class_attribute :namespace | |
class_attribute :redis | |
class << self | |
def namespace |
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
<?php // BRAD | |
$numbers = array("1", "2", "3", "4", "5"); | |
function array_print($values) { | |
$array = array_reverse($values); | |
print_values($array); | |
} | |
function print_values($array) { | |
echo array_pop($array); |
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
# you can turn two tests into one if you are testing almost the same thing | |
# example | |
before(:each) do | |
@project = Project.new | |
end | |
it "should contain errors on a blank url" do | |
@project.save | |
@project.errors.should include({:url=>["can't be blank"]}) | |
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
# you can turn two tests into one if you are testing almost the same thing | |
# example | |
before(:each) do | |
@project = Project.new | |
end | |
it "should contain errors on a blank url" do | |
@project.save | |
@project.errors.should include({:url=>["can't be blank"]}) | |
end |