Skip to content

Instantly share code, notes, and snippets.

View dallas's full-sized avatar

Dallas Reedy dallas

View GitHub Profile
@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
@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 / 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 / _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|
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 / 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;
}
@dallas
dallas / string.rb
Created February 16, 2010 19:13
add single-word boolean methods to String
class String
# alias the method_missing method chain so that we can use single-word booleans
# for example, we can do things like "standard".standard? which will give us true
# obviously this is most suited for cases where you have a variable with a value from a known set of values
def method_missing_with_single_word_booleans(method_name, *args, &block)
return method_missing_without_single_word_booleans(method_name, *args, &block) unless method_name.to_s =~ /^(\w+)\?$/
self == $1
end
alias_method_chain :method_missing, :single_word_booleans
end
@dallas
dallas / flash_message.rb
Created December 3, 2009 22:06
The beginnings of Flashtastic!
# Create a ViewHelper class or module (whatever) for dealing with flash messages in an easy-to-use format
# the current way:
<%- if flash[:error] -%>
<p class="error"><%= flash[:error] %></p>
<%- end -%>
<%- if flash[:notice] -%>
<p class="notice success">
<%= flash[:notice] %> <%= link_to('View Now', view_post_path) if post_created %>
</p>
@dallas
dallas / gist:178685
Created August 31, 2009 20:18
IRb enhancements & settings
We couldn’t find that file to show.
@dallas
dallas / gist:176414
Created August 27, 2009 16:27 — forked from laserlemon/gist:175993
software install directions by laserlemon
# Leopard Development Environment (from clean installation)
# Replace USERNAME with your OS X short name.
# Replace PASSWORD with your MySQL root password.
# Install XCode Tools
# Install MacPorts
# Install Textmate
# Generate an SSH key
ssh-keygen