Skip to content

Instantly share code, notes, and snippets.

View dallas's full-sized avatar

Dallas Reedy dallas

View GitHub Profile
@dallas
dallas / sum.js
Created May 13, 2010 04:40
creating sum functions as an exercise
// Sums all "number" arguments given. This includes floats by default.
//
// sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); //=> 55
// sum(1, "hey", 2, "3", 4, "five", 6, 'hi!', 7, 8.2, 9, 10); //=> 47.2
function sum() {
var sum = 0;
for (i = 0; i < arguments.length; i++) {
var arg = arguments[i];
if (typeof arg === 'number') sum += arg;
}
body, table, td, th, p, a, img { margin:0 auto; padding:0; }
thead, tbody, tr { margin:0; padding:0; }
body, table.body-table, table.body-table td.body-td {
background-color:#ffffff;
color:#333333;
font-family:"Lucida Grande", Arial, Helvetica, sans-serif;
font-size:16px;
line-height:24px;
margin:0;
@dallas
dallas / _smart_enumerator.rb
Created June 13, 2011 03:44
Smart enumerator with smart enumerable items
class SmartEnumerator < Enumerator
attr_reader :length
def initialize(enumerable)
super
@length = enumerable.length
end
def each
self.each_with_index do |item, index|
@dallas
dallas / rails31init.md
Created September 11, 2011 05:22 — forked from docwhat/rails31init.md
Rails 3.1 with Rspec, Factory Girl, Haml, Simple Form, Database Cleaner, Spork, and Guard

Install Rails 3.1

gem install rails

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

@dallas
dallas / aliases.zsh
Created December 19, 2012 16:57
zshell aliases
# Shell commands
alias @='pwd'
# Bundler
alias brake='bundle exec rake'
alias be='bundle exec'
# Rails 2
alias sc='script/console'
alias sg='script/generate'
@dallas
dallas / fun with Fib.rb
Created August 13, 2009 22:01
having fun with Hash initializer and the Fibonacci Sequence
# Having some fun with a simple Fibonacci sequence Hash!
fibonacci = Hash.new {|hash, key| hash[key] = hash[key - 1] + hash[key - 2]}
#=> {}
# Gotta get things started here…
fibonacci[1] = 1
#=> 1