Skip to content

Instantly share code, notes, and snippets.

# Create the associations for individual body_metrics and accept their nested
# attributes. This makes the biometrics form work and a few other things.
Dir['app/models/body_metric/*.rb'].collect { |file| File.basename(file).sub /\.rb/, '' }.each do |metric|
has_one :"current_#{metric}", -> { latest }, class_name: "BodyMetric::#{metric.camelize}"
accepts_nested_attributes_for :"current_#{metric}"
define_method("current_#{metric}") do
super() || self.send(:"build_current_#{metric}")
end
end
class Policy
attr_reader :expires, :response
def initialize user
if user
@expires = 8.hours.from_now
content_length = 100..50.megabytes
user_id = user.email.split('@').reverse.join('/')
else
@expires = 30.minutes.from_now
@cwoodcox
cwoodcox / observable.rb
Created August 27, 2013 17:36
I just wrote this. Now I understand why it's a thing. BECAUSE IT'S COOL.
module Shortwave
module Observable
def self.included(base)
base.send :include, InstanceMethods
end
module InstanceMethods
class Notification
attr_accessor :event, :id, :klass
@cwoodcox
cwoodcox / gist:5719467
Created June 6, 2013 05:16
the current state of my brew
ack
autoconf
automake
cmake
cowsay
curl-ca-bundle
ec2-api-tools
fortune
fping
freetype
@cwoodcox
cwoodcox / gist:5629263
Created May 22, 2013 17:18
Sometimes I do terrible things in Ruby. Terrible, horrible, wonderful things.
def create_stylesheet
stylesheet = StringIO.new
stylesheet << <<-EOS
@font-face {
font-family: 'badges';
src: url('#{font_eot.url}');
src: url('#{font_eot.url}') format('embedded-opentype'),
url('#{font_woff.url}') format('woff'),
url('#{font_ttf.url}') format('truetype'),
url('#{font_svg.url}') format('svg');
@cwoodcox
cwoodcox / curl command
Created May 20, 2013 20:51
problem with a hubot plugin
curl -H "Accept: application/json" \
> -u :$HEROKU_API_TOKEN \
> -d "collaborator[email]=corey%2Ewoodcox%40gmail%2Ecom" \
> -X POST https://api.heroku.com/apps/oc-little-nellie-prod/collaborators
corey.woodcox@gmail.com added as a collaborator on oc-little-nellie-prod.
@cwoodcox
cwoodcox / gist:5323288
Created April 5, 2013 22:45
quick rack config file to serve a jekyll site so i can point pow at it
require 'rack/rewrite'
use Rack::Rewrite do
rewrite '/', 'index.html'
end
run Rack::Directory.new(File.join File.dirname(__FILE__), '_site')
filter :workshop, collection: Workshop.with_registrations.collect {|w| [ "#{w.venue} – #{w.location}", w.id ]}
[28] pry(#<Module>):2> show-method nav_class
From: /Users/cwoodcox/Projects/esa/app/helpers/shim/pages_helper.rb @ line 8:
Number of lines: 7
Owner: Shim::PagesHelper
Visibility: public
def nav_class(section)
if current_section == section
"current-page"
module Compass
module SassExtensions
module Functions
module ImageSize
end
end
end
end