Skip to content

Instantly share code, notes, and snippets.

View cmdrkeene's full-sized avatar

Brandon Keene cmdrkeene

View GitHub Profile
Figure 4. Cornsweet effect makes identical regions look differently bright when separated by opposing luminance gradients that meet at an edge. Various stimuli, including a spinning black and white disk (a), can create this effect. The region adjacent to the lighter gradient appears brighter than the region next to the darker gradient (b), which is the opposite effect of the standard simultaneous brightness contrast. A graph of relative luminance (c) shows that the two areas on either side of the edge are physically identical, but a graph of the perception of brightness (d) indicates that the right side seems brighter than the left, which is the Cornsweet effect. Blocks showing the Cornsweet effect in a scene (e) enhance the illusion because the information presented increases the probability that the two blocks are differently reflective surfaces under different illuminants. The upper block now looks much darker than the lower one, even though they are identical.
@cmdrkeene
cmdrkeene / calc.rb
Created April 24, 2012 22:06
Ruby Calc
class Calc
MINUTE = 60
HOUR = 3600
DAY = 86400
WEEK = 604800
class << self
def time_of_day_weighted(value, time = Time.now.utc)
value.to_f * (time.seconds_since_midnight / DAY)
end
module Enumerable
def halve
midpoint = (size / 2.0).ceil
partition {|x| index(x) < midpoint}
end
end

State Machines in Ruby

Acts as State Machine (AASM)

gem install rubyist-aasm

Example

include AASM
class Object
TEST_FORMATTER_FILE_REGEX = /_formatter/ unless defined?(TEST_FORMATTER_FILE_REGEX)
alias :original_puts :puts
def puts(string ="")
if caller.first =~ TEST_FORMATTER_FILE_REGEX
super string
else
super string.to_s + "\s(#{caller.first.match(/(\w+\.\w+:\d+)|Rakefile:\d+/)[0]})"
end
@cmdrkeene
cmdrkeene / gist:161304
Created August 4, 2009 15:18
Forgive us, for we have sinned
# Execute a block +number+ times. Block should be a predicate (return true/false)
#
# Use procs/lambdas to define callbacks:
# :success => ...
# :retry => ...
# :failure => ...
def do_over(number, options = {}, &block)
options = {
:success => lambda { puts "SUCCESS" },
:retry => lambda { puts "RETRY" },
brandon:six-emoji{master}$ rake spec
(in /usr/local/src/workspace/six-emoji)
....FFFFF..............................
1)
NoMethodError in 'Emojicon should be creatable (sanity check)'
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?
/usr/local/src/workspace/six-emoji/spec/fixjour_builders.rb:6:in `__bind_1247435905_341143'