Skip to content

Instantly share code, notes, and snippets.

View Sutto's full-sized avatar

Darcy Laycock Sutto

View GitHub Profile
#!/bin/sh
/Users/linus/Developer/bin/fetch.rb &
@Sutto
Sutto / ap
Created January 10, 2011 06:56
Simple JSON / XML etc for APIs using HTTParty and Awesome Print
#!/usr/bin/env ruby
require 'rubygems'
require 'httparty'
require 'awesome_print'
ap HTTParty.get(ARGV[0]).parsed_response
@Sutto
Sutto / cleaner.rb
Created December 30, 2010 08:37 — forked from thomasfedb/cleaner.rb
module AttrCleaner
module ModuleMixin
def self.included(base)
base.class_eval do
extend ClassMethods
alias_method_chain :write_attribute, :cleaner
end
end
module ClassMethods
@Sutto
Sutto / luhn.rb
Created December 16, 2010 03:10 — forked from thomasfedb/luhn.rb
def luhn_valid?(number)
return unless number.is_a?(String)
# Convert to a reversed list of digits
digits = number.scan(/\d/).map(&:to_i).reverse
# No numbers in the string
return false if digits.empty?
check_digit = digits.shift
# For each of the normal integers, compute the correct sum
final_digits = []
digits.each_with_index do |value, index|
# i'd like this
%article omg
= render partial: 'omg.coffee'
# to result in this
<article>
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
raise ENV["GEM_PATH"].inspect
rescue LoadError
# RVM is unavailable at this point.
@Sutto
Sutto / gist:621632
Created October 12, 2010 03:45 — forked from sj26/gist:621629
require 'active_support/all'
class Blah
def foo
'foo!'
end
end
module Things
def self.included(base)
#
# Based upon the NCSA server configuration files originally by Rob McCool.
#
# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.2/ for detailed information about
# the directives.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
raise "Gem Path: #{Gem.path.inspect}"
rescue LoadError
# RVM is unavailable at this point.