Skip to content

Instantly share code, notes, and snippets.

View tjsingleton's full-sized avatar

TJ Singleton tjsingleton

View GitHub Profile
# 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
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;
@tjsingleton
tjsingleton / Chef Solo Bootstrap with Ruby 2.2.2
Last active November 5, 2021 21:41 — forked from nyxwulf/Chef Bootstrap Ruby 1.9.3-p194
Chef Solo Bootstrap with Ruby 2.2.2
#!/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
@tjsingleton
tjsingleton / parser_plugin.rb
Created April 26, 2011 03:50 — forked from plukevdh/parser_plugin.rb
A nonsensical example of what I want to do. Someone please fill in the blanks.
module Parser
@formats = {}
class << self
attr_accessor :formats
def create(format)
formats[format].new
end
end
# 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
<?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);
# 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
# 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