Skip to content

Instantly share code, notes, and snippets.

@danreedy
danreedy / speaker.md
Last active August 29, 2015 13:57 — forked from matiaskorhonen/speaker.md
CFP Response for Frozen Rails
@danreedy
danreedy / development.rb
Created February 21, 2014 14:30
A Chatty Unicorn
# config/environments/development.rb
# {{APP_NAME}}::Application.configure do
# ...
config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get(
ENV['LOG_LEVEL'] ? ENV['LOG_LEVEL'].upcase : 'DEBUG'
)
# ...
class UserController < ApplicationController
def create
@user = User.create(UserInput.create(params))
end
def update
@user = User.find(params[:id].to_i)
@user.update_attributes(UserInput.update(params))
end
@danreedy
danreedy / 100.rb
Created April 9, 2012 17:30
all combinations of four integers adding up to 100
haystack = []
0.upto(100) do |i|
0.upto(100) do |j|
0.upto(100) do |k|
0.upto(100) do |l|
test = [i,j,k,l].sort
unless haystack.include? test
puts "#{test.join(', ')}\n" if test.inject(&:+) == 100
haystack << test
end
@danreedy
danreedy / in_range.applescript
Created December 13, 2011 17:23
Out of Range Bluetooth Proximity Script
set t to ""
set t to do shell script "security 2>&1 find-generic-password -gl ScreenSaverPassword"
set KeyKind to "generic password"
set text item delimiters to "acct" -- Get Account name
set tlst to every text item of t
set acct to item 2 of tlst
set text item delimiters to "\""
set tlst to every text item of acct
set text item delimiters to "\"" -- Get Password
set tlst to every text item of t
@danreedy
danreedy / include-vs-extend.rb
Created October 5, 2011 19:17
Module include vs extend test. Developing a Rails engine and I want to add a method that all ActiveRecord objects will respond to when called. Refactored to use a single include
require 'minitest/autorun'
module KnightIndustries
def self.included (klass)
klass.extend ClassMethods
end
def can_talk?
false
end
@danreedy
danreedy / development.rb
Created September 20, 2011 16:06
Setting engine specific settings in global environment files
Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# <snip>
config.my_setting = "bar"
end
@danreedy
danreedy / time.rb
Created June 28, 2011 03:38
A monkey patch to check for the next business day in X number of days.
class Time
def in_business_days(number_of_days)
result = self.in number_of_days.days
while [0,6].include?(result.wday) || result.to_date.holiday?(:us)
result += 1.day
end
result
end
end
@danreedy
danreedy / gist:1027224
Created June 15, 2011 14:28
A Textmate bundle command for printing to preview from Textmate with syntax highlighting.
[ -n "$TM_FILEPATH" ] && \
PDF_FILE=~/Desktop/`date "+%y%m%d%H%M%S"`_`basename "$TM_FILEPATH"`.pdf
PS_FILE=/tmp/`basename "$TM_FILEPATH"`.ps
vim \
"+set number" "+syntax on" "+color slate" \
"+set printoptions=number:y" \
"+set printfont=consolas:h7" \
"+hardcopy > $PS_FILE" "+q" \
$TM_FILEPATH &>/dev/null && \
ps2pdf $PS_FILE $PDF_FILE && \
@danreedy
danreedy / approval.rb
Created May 23, 2011 19:05
Example Method_Missing code for an approval model
class Approval
attr_accessor :status
def method_missing(meth, *args, &blk)
method_name = meth.to_s
if method_name =~ /\?$/
self.status.downcase.eql? method_name.gsub(/\?$/,'')
else
super
end
end