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:4173831
Created November 30, 2012 04:53
Refactored recursive minimax with alpha/beta pruning (Flog score: 12)
def minimax_with_alpha(max_player = true, ply = 0, alpha = -1000, beta = 1000)
return(board.winner? ? winning_score(max_player, ply) : 0) if base_case_satisfied?
ab_value = max_player ? -1000 : 1000
ab_value, best_move = gen_score_game_tree(max_player, ply, alpha, beta, ab_value)
return( ply == 0 ? best_move : ab_value)
end
def gen_score_game_tree(max_player, ply, alpha, beta, ab_value)
best_move = 0
available_moves.each do |index|
@rewinfrey
rewinfrey / gist:4173982
Created November 30, 2012 05:50
Undoing last commit
$ git commit ... (1)
$ git reset --soft HEAD^ (2)
$ edit (3)
$ git add .... (4)
$ git commit -c ORIG_HEAD (5)
1. This is what you want to undo
2. This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset".
@rewinfrey
rewinfrey / gist:4251485
Created December 10, 2012 16:04
Minimax recursive with max/min values
def minimax_back(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
if ply >= max_ply
return(max_player ? max_score : min_score)
end
@rewinfrey
rewinfrey / YAML serialization
Created December 12, 2012 19:35
A simple example showing how attributes of objects that are objects are also serialized when we serialize the base object
require 'yaml'
class RetainAttributeOfToYaml
attr_accessor :name
def initialize(name)
@name = "Hi, my name is #{name}."
end
end
class ToYaml
@rewinfrey
rewinfrey / Setup Autotest with Rspec v. 2 (For Ruby and Rails Projects)
Created December 13, 2012 19:04
How to setup Autotest with Rspec v. 2..
Install the necessary gems:
$ gem install autotest
$ gem install autotest-growl
$ gem install autotest-fsevent
note: you may also need the "autotest-rails-pure" gem
Create ~/.autotest configuration file (include the following script):
@rewinfrey
rewinfrey / gist:4320190
Created December 17, 2012 17:35
Using old version of LimeLight
$ rvm install jruby-1.6.6
https://github.com/slagyr/limelight/downloads
download: limelight_docs.llp
$ gem install limelight -v 0.5.5
$ limelight open limelight_docs.llp
@rewinfrey
rewinfrey / gist:4421712
Created December 31, 2012 18:11
Audio file conversion for Josh (m4a to mp3)
First, we need FFMpeg's binary (put binary where it can be found in the load path):
http://ffmpegmac.net/
Next, in order to encode a file as mp3, we need Lame (currently tested with 3.99.5):
http://sourceforge.net/projects/lame/files/lame/3.99/
Untar the library:
$ tar -zxvf { file_name }
Run Lame's configure script (using the default configuration for this is fine):
@rewinfrey
rewinfrey / gist:4485739
Created January 8, 2013 17:15
SOLID example for Alfonso
# don't really need Shape class
class Shape
def initialize(options)
end
def area
end
end
class CircleShape
@rewinfrey
rewinfrey / gist:4611225
Last active December 11, 2015 13:58
What Is Self?
class SelfMaker
def yet_what_is_self?
self.class.class_eval do
mirror(self, "Inside class_eval of SelfMaker#yet_what_is_self?")
end
instance_eval do
mirror(self, "Inside instance_eval of SelfMaker#yet_what_is_self?")
end
@rewinfrey
rewinfrey / gist:4635346
Created January 25, 2013 15:39
Dependency Inversion Violation For Kelly
class PlayerIO
attr_accessor :output, :input
def initialize(output, input)
@output = output
@input = input
end
def output(args)
@output.puts args
end