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
func composeAndApply<T>(funcs: (T -> T)[], val: T) -> T { | |
return funcs.reduce(val, combine: { (memo, aFunc) in aFunc(memo) }) | |
} | |
func square(val: Int) -> Int { | |
return val * val | |
} | |
func double(val: Int) -> Int { | |
return val * 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
class Mutator { | |
var mutated: Bool | |
init() { | |
mutated = false | |
} | |
func mutate() { | |
mutated = true | |
} | |
} |
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
# Exactly 140 characters! :) | |
# We rescue StandardError and re-raise a RuntimeError | |
# because that's nicer than getting NoMethodError or TypeError | |
def play a, b | |
t = %w(scissors paper rock lizard spock) | |
['tie', b, a, b, a][(t.index(a)-t.index(b)) % 5] | |
rescue StandardError | |
raise 'invalid' | |
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
func unwrap<T>(wrapped: T?) throws -> T { | |
guard let unwrapped = wrapped else { | |
throw NSError(domain: "custom", code: 1, userInfo: nil) | |
} | |
return unwrapped | |
} |
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
parse_git_branch(){ | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
parse_home_dir(){ | |
pwd -P | sed -e "s/^$(echo $HOME | sed -e 's/\//\\\//g')/~/" -e 's/~\/Development/~\/dev/' | |
} | |
PS1="\$(parse_home_dir)\$(parse_git_branch) $ " |
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
lower_bound = (ARGV.shift || 2).to_i | |
upper_bound = (ARGV.shift || 35).to_i | |
iterations = (ARGV.shift || 20_000).to_i | |
(lower_bound..upper_bound).each do |person_count| | |
matches = 0 | |
iterations.times do | |
matches += 1 if (1..person_count).map{|p| rand(365)}.uniq! | |
end | |
puts "Person count: %3d Success: %3.1f" % |
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
' MACRO NAME: | |
' AddQuantity | |
' AUTHOR: | |
' Bradley Grzesiak | |
' FUNCTION: | |
' Increments the quantity of one or many dimensions in a drawing | |
' INSTALL: | |
' Create a "New Macro Button" via Tools->Customize->Commands->Macro in a toolbar. | |
' It is highly recommended that you assign a keystroke to this macro. I use "q" | |
' COMPATIBILITY: |
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
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') | |
describe "/users/index.html.haml" do | |
include UsersHelper | |
fixtures :users | |
before(:each) do | |
assigns[:users] = users | |
print "\nuser size: #{users.size}\n" | |
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
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
describe StoriesController do | |
def mock_story(stubs={}) | |
@mock_story ||= mock_model(Story, stubs) | |
end | |
def mock_errors(stubs={}) | |
unless @mock_errors | |
@mock_errors = mock(:errors, stubs) | |
@mock_errors.should_receive(:on).with(:text).and_return("error on :text") |
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
Shoes.setup do | |
gem 'activeresource' | |
end | |
require 'activeresource' | |
class Person < ActiveResource::Base | |
self.site = 'http://0.0.0.0:3000' | |
end |
OlderNewer