Skip to content

Instantly share code, notes, and snippets.

View thefonso's full-sized avatar

thefonso thefonso

View GitHub Profile
@thefonso
thefonso / about.md
Created July 3, 2012 16:44 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@thefonso
thefonso / gist:3375436
Created August 17, 2012 02:42 — forked from jugyo/gist:865454
TextMate command to convert haml to html
#!/usr/bin/env ruby
# Input: Selected Text or Nothing
# Output: Replace Selected Text
require 'tempfile'
def unindent(text)
lines = text.split(/\n/)
level = lines.map{|l| l[/^\s*/].size}.min
@thefonso
thefonso / example2.js
Created November 15, 2012 18:16 — forked from anonymous/example2.js
MongoDB map reduce example 2
// suggested shell cmd line to run this:
//
// mongo --shell example2.js
//
// Note: the { out : … } parameter is for mongodb 1.8+
db.things.insert( { _id : 1, tags : ['dog', 'cat'] } );
db.things.insert( { _id : 2, tags : ['cat'] } );
db.things.insert( { _id : 3, tags : ['mouse', 'cat', 'dog'] } );
db.things.insert( { _id : 4, tags : [] } );
ruby code:
spec code:
All test are green now. this is leading me to create a new mechanism for game state in my app.
[
the new game_state will have
if returned value == 1 => win
elsif returned value == -1 => loose
else => draw
@thefonso
thefonso / theme.html
Created December 1, 2012 21:34 — forked from soemarko/theme.html
embed github gist to tumblr
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@thefonso
thefonso / attempt_win.rb
Created December 1, 2012 21:44
attempt_win method
def attempt_win(board)
ai_winmoves = {
:wm01 => {:a1=>"O", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "},
:wm02 => {:a1=>" ", :a2=>"O", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "},
:wm03 => {:a1=>" ", :a2=>" ", :a3=>"O", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "},
:wm04 => {:a1=>" ", :a2=>" ", :a3=>" ", :b1=>"O", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "},
:wm05 => {:a1=>" ", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>"O", :c1=>" ", :c2=>" ", :c3=>" "},
:wm06 => {:a1=>" ", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>"O", :c2=>" ", :c3=>" "},
:wm07 => {:a1=>" ", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>"O", :c3=>" "},
:wm08 => {:a1=>" ", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>"O"},
@thefonso
thefonso / gist_line_numbers.css
Created December 1, 2012 22:21 — forked from potch/gist_line_numbers.css
CSS to add line numbers to embedded gists
.gist-highlight {
border-left: 3ex solid #eee;
position: relative;
}
.gist-highlight pre {
counter-reset: linenumbers;
}
.gist-highlight pre div:before {
@thefonso
thefonso / gistembed.js
Created December 1, 2012 22:41 — forked from vitorbal/gistembed.js
Use writeCapture to embed gists to Tumblr
$(document).ready(function() {
var prefix = "https://gist.github.com/";
$('a[href^="' + prefix + '"]').each(function(i) {
var $anchor = $(this),
$el = $("<p></p>");
$anchor.replaceWith($el);
writeCapture.html($el, '<script src="'+$anchor.text()+'.js"></scr' + 'ipt>');
$anchor.remove();
});
});
@thefonso
thefonso / regular.rb
Created December 3, 2012 15:35
refactored ai player class
class Computer
include Algorithm::Regular
def move(board)
@player_symbol = 'O'
puts "computer move..."
ai_moves(board)
end
@thefonso
thefonso / regular_non_refactored.rb
Created December 3, 2012 15:40
original computer ai class
class Computer
def move(board)
@player_symbol = 'O'
puts "computer move..."
taken_moves = board.grid.select{ |k, v| v != " " }.keys.length
if taken_moves == 1
@move = ai_first_move(board)
elsif board.grid[:b2] != " " and taken_moves == 3