Skip to content

Instantly share code, notes, and snippets.

Avatar

Carin Meier gigasquid

View GitHub Profile
View mutualRecursionStackTooDeep.rb
# An example of Mutual Recursion.
# A simple lexer for our parser. We only return tokens for :numbers
# and +, - and new lines.
class Lexer
attr_reader :token, :type
def initialize(stream)
@stream = stream
@tokens = []
@gigasquid
gigasquid / bowling.clj
Created Mar 30, 2011
First Clojure Kata for Bowling
View bowling.clj
(ns bowling-game.game)
(defrecord Frame [pins-hit-list])
(defrecord Game [frame-list])
(defn construct-frame [pins]
(Frame. [pins]))
(defn construct-empty-frame []
@gigasquid
gigasquid / aprilshowers.clj
Created Apr 3, 2011
April Showers Bring May Flowers
View aprilshowers.clj
;;;;April Showers bring May Flowers
(ns my.april.showers)
(def sleep-time 20)
(def frame (java.awt.Frame.))
(defn show-frame [frame x y]
(doto frame
(.setVisible true)
(.setSize (java.awt.Dimension. x y)) ))
@gigasquid
gigasquid / mymethod.js
Created May 5, 2011
Example File for Ajax Mocking with Jasmine
View mymethod.js
function mymethod()
{
var url = contextPath + "/bar.ajax";
$.ajax({
type: "POST",
url: url,
data: { type: "test"},
success: function(json){
$('#mydiv').html("Happy Face");
@gigasquid
gigasquid / mymethodTest.js
Created May 5, 2011
Example Spec File for Ajax Mocking with Jasmine
View mymethodTest.js
describe("Mocking Ajax Calls", function() {
beforeEach(function() {
loadFixtures('test.html');
//mocking ajax call with Jasmine Spies
var fakeData = "You can put your return data here";
spyOn($, "ajax").andCallFake(function(params) {
params.success(fakeData);
});
});
View roman_number_converter.rb
# Given a integer between 1 and 50 convert it to its Roman Numeral
def convert_to_roman (arabic)
ones_translation =
[ 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']
tens_translation =
[ 'X', 'XX', 'XXX', 'XL', 'L']
tens = ""
@gigasquid
gigasquid / sort-users.clj
Created Jun 16, 2011
Sort Users 4Clojure
View sort-users.clj
(defn users-comp [x y]
(let [xsolved (count (:solved x))
ysolved (count (:solved y))
xlastlogin (:last-login x)
ylastlogin (:last-login y)]
(cond (> xsolved ysolved) 1
(< xsolved ysolved) -1
(and xlastlogin (nil? ylastlogin)) 1
(and ylastlogin (nil? xlastlogin)) -1
(and xlastlogin ylastlogin (.after xlastlogin ylastlogin)) 1
View roman-number-converter.clj
(ns roman-nums
(:use clojure.test))
(def chart (zipmap [1 4 5 9 10 40 50 90 100 400 500 900 1000]
["I" "IV" "V" "IX" "X" "XL" "L" "XC" "C" "CD" "D" "CM" "M"]))
;; Using no tail recursion
(defn arabic-to-roman [n]
(let [[val c] (last
View gist:2296953
;; Current version -- note the use of `when-valid`... it is essentially duplicating the work the
;; syntax-validation-m monad should be able to handle, so I've been attempting to
;; clean it up / refactor it to use only the monad
(defmacro expect
"Run the call form, check that all the mocks defined in the fakes
(probably with 'fake') have been satisfied, and check that the actual
results are as expected. If the expected results are a function, it
will be called with the actual result as its single argument.
View gist:2296961
;; Current version -- note the use of `when-valid`... it is essentially duplicating the work the
;; syntax-validation-m monad should be able to handle, so I've been attempting to
;; clean it up / refactor it to use only the monad
(defmacro expect
"Run the call form, check that all the mocks defined in the fakes
(probably with 'fake') have been satisfied, and check that the actual
results are as expected. If the expected results are a function, it
will be called with the actual result as its single argument.