Skip to content

Instantly share code, notes, and snippets.

class StringJoiner
def call string1, string2
"#{string1}#{string2}"
end
end
join = StringJoiner.new
join.call("this ", "is normal")
# => "this is normal"
@cwoodcox
cwoodcox / tmux.conf
Created November 19, 2014 18:46
My interactive project opening thing
# Open a project interactively
unbind C-p
bind-key C-p \
command-prompt -p "client:","project:" "\
new-session -A -c ~/Projects/%1/%2 -s %2 -n code 'reattach-to-user-namespace -l vim'\;\
new-window -d -n console 'tail -f log/development.log'\;\
split-window -v -t 1 'rails c'\;\
next-window"
@cwoodcox
cwoodcox / logged-in
Created November 19, 2014 18:08
Weird
Started GET "/products/die-cut-stickers" for 127.0.0.1 at 2014-11-19 12:47:59 -0500
Processing by Spree::ProductsController#show as HTML
Parameters: {"id"=>"die-cut-stickers"}
Spree::Preference Load (0.4ms) SELECT "spree_preferences".* FROM "spree_preferences" WHERE "spree_preferences"."key" = 'spree/frontend_configuration/locale' LIMIT 1
Spree::User Load (0.3ms) SELECT "spree_users".* FROM "spree_users" WHERE "spree_users"."deleted_at" IS NULL AND "spree_users"."id" = 1 ORDER BY "spree_users"."id" ASC LIMIT 1
Spree::Store Load (0.3ms) SELECT "spree_stores".* FROM "spree_stores" WHERE (url like '%rockin-stickers.dev%') ORDER BY "spree_stores"."id" ASC LIMIT 1
Spree::Store Load (0.3ms) SELECT "spree_stores".* FROM "spree_stores" WHERE "spree_stores"."default" = 't' ORDER BY "spree_stores"."id" ASC LIMIT 1
Spree::Order Load (0.4ms) SELECT "spree_orders".* FROM "spree_orders" WHERE "spree_orders"."completed_at" IS NULL AND "spree_orders"."currency" = 'USD' AND "spree_orders"."guest_
require 'builder'
# 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');