Skip to content

Instantly share code, notes, and snippets.

View rewinfrey's full-sized avatar
🏄‍♂️
fix f = let x = f x in x

Rick Winfrey rewinfrey

🏄‍♂️
fix f = let x = f x in x
View GitHub Profile
@rewinfrey
rewinfrey / gist:3376314
Created August 17, 2012 05:57
Checking HTML body of email sent with ActionMailer
ActionMailer::Base.deliveries.first.html_part.decoded
@rewinfrey
rewinfrey / gist:3843070
Created October 5, 2012 23:33
Rails Bootstrap Dropdown nav not working
Changing order of inclusions breaks development mode, so did not changed it.
Development mode without assets precompiled works fine.
Development mode with assets precompiled broken.
Production mode (assets precompiled of course) works fine.
Commenting-out config.assets.debug = true in config/environments/development.rb fixes development mode when assets precompiled.
The last thing looks very strange. Some black magic definitely involved.
@rewinfrey
rewinfrey / gist:4066547
Created November 13, 2012 15:58
RVM Gemset Roundup
Basic commands:
rvm gemset create <name>
rvm gemset list
rvm gemset use <name>
rvm gemset delete <name>
Global gemsets:
RVM provides @global gemset for each version of Ruby
Installing a gem to this gemset makes it available to all gemsets for that version of Ruby
@rewinfrey
rewinfrey / gist:4066916
Created November 13, 2012 16:49
Bundle Can't Build Native C Extensions (after installing Mountain Lion)
brew --version
should report 0.9.3 or greater
if you have a older version then update it:
brew update
now you can install gcc-4.2 and create a symbolink link to the correct dir
brew tap homebrew/dupes
@rewinfrey
rewinfrey / gist:4066999
Created November 13, 2012 17:01
Creating New Rails App With PostGres
$> rails new myapp --skip-test-unit --database=postgresql
$> rvm gemset create myapp
$> rvm gemset use myapp
$> include 'rspec-rails' in Gemfile
$> bundle install
@rewinfrey
rewinfrey / gist:4116604
Created November 20, 2012 07:38
to_proc & map
def meth(a, b, c)
[c, b, a]
end
ary = [1, 2, 3]
meth(*ary) # => [3, 2, 1]
class Symbol
def to_proc2
Proc.new { |element| element.send self }
end
@rewinfrey
rewinfrey / gist:4152978
Created November 27, 2012 07:40
RSpec expectations
Index:
1. should() #basic expectation
2. should_not() #basic negation of an expectation (RSpec does not support using !=)
3. include(item) #called on an enumerable object, this returns true or false if the object is found in the enumerable collection
4. respond_to(:message) #determines if a particular message (as a symbol) is defined for an object
5. raise_error(type, message) #checks if a particular error was raised, accepts zero, one or two parameters
@rewinfrey
rewinfrey / gist:4159483
Created November 28, 2012 06:50
Recursive minimax with alpha/beta prunning (first version)
def minimax(max_player = true, ply = 0, alpha = -9999, beta = 9999)
# Return from recursive calls for the following escape conditions:
# 1. winning move found
# 2. resulting game tree ended in a draw
if board.winner?
# to differentiate between a win later in the game tree versus near the root, we + or - the ply from alpha or beta,
# depending on if the current move represents a win for the max player, or the min player, respectively.
return(max_player ? (-9999 + ply) : (9999 - ply))
@rewinfrey
rewinfrey / gist:4170724
Created November 29, 2012 17:50
Basic minimax recursion
def minimax(max_player = true, ply = 0, min_score = 1000, max_score = -1000)
if board.winner?
return(max_player ? (-1000 + ply) : (1000 - ply))
elsif board.draw_game?
return 0
end
best_move = 0
available_moves.each do |index|
@rewinfrey
rewinfrey / gist:4171586
Created November 29, 2012 20:11
Minimax recursive alpha/beta refactored as hash
def minimax_with_alpha(max_player = true, ply = 0, alpha = -9999, beta = 9999)
if board.winner?
return winning_score(max_player, ply)
elsif board.draw_game?
return 0
end
current_round = gen_score_game_tree(max_player: max_player,
alpha: alpha,
beta: beta,