Skip to content

Instantly share code, notes, and snippets.

@ptn
ptn / rockbottom.rb
Created October 10, 2011 04:16
My solution to Puzzle Node's "Hitting Rock Bottom"
# TODO
#
# Handle adding more water units than cave capacity (use something like
# cave.overflow?)
module RockBottom
#
# Represents one column in the cave.
#
# You only care about how many water units the column contains - which is
@ptn
ptn / Chess Validator
Created December 20, 2011 17:00
Chess Validator
module Chess
module Pieces
#
# Implements a basic, abstract chess piece.
#
# This piece can move to any square on the board provided that
# said square is either empty or occupied by an enemy piece - this
# guy teleports. It's the subclass' responsibility to provide the
@ptn
ptn / Six Degrees of Separation.rb
Created December 20, 2011 17:01
Six Degrees of Separation
require 'set'
#
# Analyzes Twitter conversations.
#
# Usage:
#
# Instantiate a TwitterConversation::Graph object and feed it some
# sample tweets:
#
@ptn
ptn / Poor Man's Forth
Created December 20, 2011 17:51
Poor Man's Forth
module Stacker
module Construct
class Construct
# Read extra data from the input, parse it and return the new position
# from where to continue parsing or nil if a grammar error is found.
def parse(input, pos)
pos
end
#! /usr/bin/env ruby
require 'irb'
dir = File.expand_path("~/.draughts/")
unless File.directory? dir
print "LOG: ~/.draughts dir does not exist, creating..."
Dir.mkdir dir
puts "done."
end
class MarkovChain
def initialize(states, transitions=nil)
@states = states
@graph = empty_graph
@transitions = build_transitions(transitions) if transitions
end
def transitions=(transitions)
@graph = empty_graph
@transitions = build_transitions(transitions) if transitions
# Run from bin/testbot
Draughts::AI::Board.each do |b|
Draughts::AI::Move.each do |m|
['black', 'white'].each do |c|
p = Draughts::AI::Play.first(board: b, move: m, color: c)
if p
result = p.legal
Draughts::AI::Play.all(board: b, move: m, color: c).destroy
Draughts::AI::Play.create(board: b, move: m, color: c, legal: result)
end
<?php
require_once('../wp-load.php');
/*
* --------------------------------------------------------------------
* SELECT
* --------------------------------------------------------------------
/*
@ptn
ptn / s.rb
Created April 11, 2012 14:19 — forked from jacksonwillis/s.rb
Sentences as Ruby code
class S; def initialize *w; @s=w; end; def method_missing *w;@s<<w;self;end;def
to_ary;[@s.map{ |e| e=~/[\,\.\:\-\(\)\/\'\"]/?[e]:[" ",e] }.join.strip];end;end
def Object.const_missing(c);S.new c;end; ###### https://gist.github.com/2354740
puts This.is.a.sentence.represented.by.a.Ruby.expression(",").try.it.out! #####
$(document).ready ->
if $("#map").length > 0
class MapManager
constructor: ->
@defaultLat = -12.043333
@defaultLng = -77.028333
@latEl = $("#experience_latitude")
@lngEl = $("#experience_longitude")
coords = @initialCoords()