Skip to content

Instantly share code, notes, and snippets.

@stephenaument
stephenaument / bwi-base.rb
Created October 12, 2012 15:15
bwi_respond_with method
module ActionController #:nodoc:
class Base
def bwi_respond_with(*resources, &block)
options = {}
methods = [:pkid]
options = resources.pop if resources.size > 1 && resources.last.is_a?(Hash)
if options[:methods]
if options[:methods].is_a?(Array)
@stephenaument
stephenaument / split.rb
Created February 11, 2013 21:55
Ruby script to split a 60 minute mp3 file into two minute segments with a five second overlap.
#! /usr/bin/ruby
# Split the given mp3 file into 2:05 minute pieces
file_name = ARGV[0]
# file_length = ARGV[1]
dir_name = file_name.split('.').first
`mkdir #{dir_name}`
class Duck < ActiveRecord::Base
def awake?
status == 'awake'
end
def quack
puts quack_style
end
end
class NilObject
def initialize(klass=nil)
@klass=klass
end
def method_missing(name, *args)
return self unless @klass
klass.new.respond_to? name ? self : super
end
end
var options = {
"gender": "#{search_params['gender']}",
"age": "#{current_user.age}",
"language": "#{search_params['language']}",
var options = {
"gender": "#{search_params['gender']}",
"age": "#{current_user.age}",
"language": "#{search_params['language']}",
var options = {
"gender": "M",
"age": "27",
"language": "",
"query": "specials",
"properties":
};
var options = {
"gender": "M",
"age": "27",
"language": "",
"query": "specials",
"properties": {}
};
@stephenaument
stephenaument / nil_duck_final.rb
Last active August 29, 2015 13:57
2014-03-11 Null Object Part 2
class NilDuck < NilObject
def name
'Demo Duck'
end
def status
'sleeping'
end
def color
@stephenaument
stephenaument / create_ducks_migration1.rb
Created March 8, 2014 07:22
The Null Object Pattern
class CreateDucks < ActiveRecord::Migration
def change
t.string name
t.string status
t.integer hunger
t.string quack_style
t.string color
t.migratory boolean
end
end