Skip to content

Instantly share code, notes, and snippets.

View kognate's full-sized avatar

Joshua Smith kognate

  • Pittsburgh, PA
View GitHub Profile
require 'rubygems'
require 'spec'
class RDingus
def initialize(parent = nil, invocation = nil)
@parent = parent
@invocation = invocation
@invocation_exceptions = InvocationList.new
@invocation_expectations = InvocationList.new
@invocation_expectation_set = InvocationList.new
@kognate
kognate / gist:126315
Created June 9, 2009 06:21
clojure code
; now with multimethods.
(ns properties)
(defn from_string_file
[fname]
{:propfile :text :filename fname})
(defn from_xml_file
[fname]
{:propfile :xml :filename fname})
(defn to_string_file
(use 'clojure.contrib.datalog)
(use 'clojure.contrib.datalog.rules)
(use 'clojure.contrib.datalog.database)
(use 'clojure.contrib.datalog.util)
(def d (make-database
(relation :person [:name :room-id :seat-number])
(index :person :name)))
(def db (add-tuples d
module Temporal
def to_human_minutes(minutes)
_h = minutes % 60
if _h > 0
sprintf("%d hours and %s",_h,ActionView::Helpers::TextHelper.pluralize((minutes / 60).to_i,"minute"))
else
ActionView::Helpers::TextHelper.pluralize((minutes / 60).to_i,"minute")
end
end
public funciton testLogin() {
/* in this case $this->f is a User object */
$r = new ReflectionObject($this->f);
$m = $r->getMethod('login');
$this->assertEquals(2,$m->getNumberOfParameters());
}
Broken Function:
function bob(a) {
var str = a;
return a.map(function() { a + 1 })
}
Tables:
/**
* winCount
* returns the count of all games that the human player won.
*
* @returns int
*/
+(int) winCount {
NSError *error;
NSManagedObjectContext *context = [(BFHeartsAppDelegate *)[UIApplication sharedApplication].delegate managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"GameFinalScore" inManagedObjectContext:context];
@kognate
kognate / basic.thrift
Created January 9, 2011 21:53
basic thrift file
enum PhoneType {
MOBILE,
HOME,
OFFICE
}
struct PhoneNumber {
1: PhoneType ptype,
2: string name,
3: string number
@kognate
kognate / conway.rb
Created February 24, 2011 02:10
I worked on this for another twenty minutes or so. found the bug. Run it in a terminal and you can see it run.
class Conway
attr_reader :displayrange
attr_accessor :board
# Any live cell with fewer than two live neighbours dies, as if caused by under-population.
# Any live cell with two or three live neighbours lives on to the next generation.
# Any live cell with more than three live neighbours dies, as if by overcrowding.
# Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
def initialize disprange = nil
@board = { 1 => { 2 => 1}, 2 => { 2 => 1}, 3 => { 2 => 1} }
@displayrange = disprange.nil? ? (0..10) : disprange
@kognate
kognate / gist:994423
Created May 27, 2011 00:40
tumbledry
require 'yaml'
class Tumbledry
attr_accessor :patterns
def initialize
File.open('repetative.txt', 'r') do |f|
@data = f.read()
end
self.patterns = {}
@numpat = 1
end