Skip to content

Instantly share code, notes, and snippets.

[4] pry(#<HighVoltage::PagesController>)> params
=> {"things"=>{"stuff"=>"123"},
"id"=>"landing_page",
"controller"=>"high_voltage/pages",
"action"=>"show"}
[5] pry(#<HighVoltage::PagesController>)> params.fetch(:stuff){ Hash.new }
=> {}
[6] pry(#<HighVoltage::PagesController>)> params
=> {"things"=>{"stuff"=>"123"},
"id"=>"landing_page",
@iamvery
iamvery / thoughts.md
Created May 8, 2014 02:04
Thoughts on contracts.ruby

I watching the demo/use cases video for contracts.ruby and recorded some thoughts.

Use case 1

The use case states that you can avoid bugs like needing string keys instead of symbol keys be enforcing a contract that requires the method input to be a string.

IMO you should instead create a flexible interface that will allow any "stringable" input to be given to the method. That is, use the implicit string conversion methods to_s to make a string of it for indexing into the hash.

Use case 2

require 'contracts'
include Contracts
class ConvertableToHash
def self.valid?(thing)
thing.to_h
true
rescue TypeError
false
@iamvery
iamvery / a-readme.md
Last active August 29, 2015 14:01
Conway's Game of Life, written in Ruby

Conway's Game of Life, written in Ruby

Run the game

ruby driver.rb

Run the specs

rspec game_of_life_spec.rb
Io 20110905
Io> t1 := Object clone
==> Object_0x7f82795c83d0:
Io> t2 := Object clone
==> Object_0x7f827a803790:
Io> t1 isIdenticalTo(t2)
==> false
Io> t1 isIdenticalTo = method(true)
@iamvery
iamvery / a-readme.md
Last active August 29, 2015 14:01
Conway's Game of Life, written in io

Conway's Game of Life, written in io

Run the game

io driver.io

Run the specs

io cell_spec.io
@iamvery
iamvery / conway.coffee
Created June 3, 2014 18:59
Game of Life WIP with @nybblr
# Live cells with < 2 living neighbors dies to underpop
# > 3 living neighbors dies to overpop
# Otherwise, lives!
#
# Dead cells with exactly 3 living neighbors is born
# . 0 .
# . 0 .
# . 0 .
#
@iamvery
iamvery / type-constraints.swift
Created June 26, 2014 00:55
swift generic type constraints
protocol Foobery {
func asFoo() -> String
}
extension String: Foobery {
func asFoo() -> String {
return "foo"
}
}
class Bar {}
class Baz {
init(str: String!) {
println(str)
}
}
class Foo: Bar {
let bar: String!
#!/bin/sh
file=$1
exec=$(echo $file | awk -F\. '{print$1}')
xcrun swift "$file" && ./"$exec"