Skip to content

Instantly share code, notes, and snippets.

@dustMason
dustMason / lan.rb
Last active December 13, 2015 22:39
A ruby version of the Letters and Numbers "Numbers Round" solver. Check my previous gist for a Scala version with more info. REQUIRES RUBY 2.0! due to use of lazy enumerators.
class Equation
attr_reader :ops
def initialize(ops)
@ops = ops
end
def calc
calc_rec(@ops)
@dustMason
dustMason / about.md
Last active December 13, 2015 20:58
Letters and Numbers "Numbers Round" solver in Scala

A Scala object capable of coming up with the best answer during "Numbers Rounds" of the famous TV game-show Letters and Numbers. Uses Streams and lazy evaluation for a nicely performant solution.

see http://en.wikipedia.org/wiki/Letters_and_Numbers for more

One contestant chooses how many "small" and "large" numbers they would like to make up six randomly chosen numbers. Small numbers are between 1 and 10 inclusive, and large numbers are 25, 50, 75, or 100. All large numbers will be different, so at most four large numbers may be chosen. The contestants have to use arithmetic on some or all of those numbers to get as close as possible to a randomly generated three-digit target number within the thirty second time limit. Fractions are not allowed—only integers may be used at any stage of the calculation.

@dustMason
dustMason / game.coffee
Last active March 2, 2017 19:18
Simple console-based Letters and Numbers game – only the "Numbers" version. Requires node.js, coffeescript module and prompt (`npm install -g prompt`) Run with `coffee game.coffee`
prompt = require('prompt')
class Player
constructor: (@name,@deck)->
@cards = []
@ops = ["+","-","*","/"]
@chooseCards()
chooseCards: (slots=6)->
for slot in [0..slots-1]
i = Math.floor(Math.random()*@deck.length)
@dustMason
dustMason / 1 spec_helper.rb
Created September 16, 2012 22:17
Poltergeist Issue #155
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# require 'rspec/autorun'
require 'capybara/rails'
require 'capybara/poltergeist'
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {
# phantomjs_options: ['--cookies-file=/Users/turtle/Desktop/cookies.txt']
})
@dustMason
dustMason / geocoder.coffee
Created August 14, 2012 00:34
The simplest geocoder ever. CLI thingy using node.js and the Google Maps API. Enter a place, get lat + lng
prompt = require 'prompt'
gm = require 'googlemaps'
red = '\u001b[31m'
blue = '\u001b[34m'
reset = '\u001b[0m'
l = (content) ->
console.log content
@dustMason
dustMason / cached_finder.rb
Created February 24, 2012 17:45
CachedFinder Extension for ActiveRecord
require 'digest/sha1'
module Extensions
module CachedFinder
extend ActiveSupport::Concern
module ClassMethods
def cached(options = {})
options_hash = Digest::SHA1.hexdigest(options.to_s)
Rails.cache.fetch [self.class.to_s.underscore, options_hash].join('/'), :expires_in => 1.hour, :race_condition_ttl => 10 do
all options
@dustMason
dustMason / index.js.erb
Created December 17, 2011 04:16 — forked from ryanb/index.js.erb
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
@dustMason
dustMason / scorekeeper.rb
Created November 22, 2011 12:51
ScoreKeeper.rb : A quick command-line app written in Ruby for keeping score during Gin Rummy games. Run `ruby scorekeeper.rb` to start the game.
module ScoreKeeper
class Player
attr_accessor :name, :scores
def initialize(name)
@name = name
@scores = []
end
def <<(points)
@scores << points
ruby-1.9.2-p180 :061 > Signup.last
Signup Load (0.4ms) SELECT "signups".* FROM "signups" ORDER BY "signups"."token" DESC LIMIT 1
#<Signup:0x0000010a51f5a8> {
:token => "ab377c84",
:email => "[email protected]",
:referred_by => nil,
:notified => nil,
:user_id => nil,
:created_at => Tue, 01 Nov 2011 13:25:06 PDT -07:00,
:updated_at => Tue, 01 Nov 2011 13:25:06 PDT -07:00,
@dustMason
dustMason / gist:1252515
Created September 30, 2011 02:34
Fix precompilation DB dependency
namespace :assets do
# Prepend the assets:precompile_prepare task to assets:precompile.
task :precompile => :precompile_prepare
# This task will be called before assets:precompile to optimize the
# compilation, i.e. to prevent any DB calls.
task 'precompile_prepare' do
# Without this assets:precompile will call itself again with this var set.
# This basically speeds things up.
# ENV['RAILS_GROUPS'] = 'assets'