This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# quick and dirty monkey patch to see which `require`d files are taking a long time to load | |
# Usage: 'require "benchmarking_require"' in spec_helper.rb | |
require "benchmark" | |
module Kernel | |
def require_with_benchmark path | |
x = nil | |
m = Benchmark.measure do | |
x = require_without_benchmark path | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for use by collection_select and friends, to link a human-readable label with a db-friendly symbolic value | |
# todo: ActiveRecord macros for setters (for allowing multiple values or just one) | |
# Usage: | |
# Table name: snacks | |
# id :integer | |
# ice_cream :string | |
# class Snack < ActiveRecord::Base | |
# FLAVORS = Enum.new [ | |
# [:vanilla, "Vanilla"], | |
# [:chocolate, "Chocolate"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal < ActiveRecord::Base | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Based on http://jollyjinx.tumblr.com/post/34638496292/fusion-drive-on-older-macs-yes-since-apple-has | |
# To use this, first create a corestorage drive - see e.g. http://www.cnet.com/how-to/how-to-make-a-custom-corestorage-drive-in-os-x/ | |
# -- it'll look something like this: | |
# | |
# diskutil list # and figure out which actual drives you want to join | |
# diskutil cs create FusionGroup disk0 disk2 # or whichever two drives | |
# diskutil cs list # and note the Logical Volume Group ID | |
# diskutil cs createVolume GROUPID jhfs+ Fused 100% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
module Kernel | |
alias :λ :lambda | |
end | |
class Hash | |
alias :+ :merge | |
alias :<< :merge! | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(id)initWithFile: (NSString*)file | |
{ | |
if (self = [super init]) { | |
self.file = file; | |
NSString* path = [[NSBundle mainBundle] pathForResource:self.file ofType:@"caf"]; | |
self.fileUrl = [NSURL fileURLWithPath:path]; | |
NSAssert(self.fileUrl, @"URL is valid."); | |
self.players = [NSMutableArray arrayWithCapacity:2]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
demonstration of https://github.com/rails/rails/issues/7690 in a vanilla rails 3.2.8 app | |
TL;DR: Foo.create(user_id: bob) sets foo's user id to 1, no matter bob's actual id | |
sesame:rails_bug [ruby-1.9.3-p194] alex$ cat app/models/user.rb | |
class User < ActiveRecord::Base | |
attr_accessible :name | |
has_many :articles | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def run delay | |
chars = File.read("./afgan.demo").split(//) | |
chars.each do |ch| | |
$stdout.print ch | |
$stdout.flush | |
sleep delay | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe ApplicationHelper do | |
describe "full_title" do | |
it "includes the page name" do | |
full_title("foo").should include("foo") | |
end | |
it "includes the base name" do | |
full_title("foo").should include("Ruby on Rails Tutorial Sample App") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Listing 4.3. The sample application site layout. | |
# app/views/layouts/application.html.erb | |
<title><%= full_title(yield(:title)) %></title> |
NewerOlder