Skip to content

Instantly share code, notes, and snippets.

View ckirkendall's full-sized avatar

Creighton Kirkendall ckirkendall

  • Blue Manta Consulting
  • Cincinnati, Ohio
View GitHub Profile
@ckirkendall
ckirkendall / gist:1380756
Created November 20, 2011 19:36
4clojure registration test
(deftest test-do-register
(let [uname "username"
lngname "thisisalongusername"
bname "$#%^$djc"
pwd "password"
shpwd "pass"
email "test@test.com"
bemail "testing.com"]
(em/defsnippit snippit1 "templates/template1.html" [:tbody :> 'first-child]
[fruit quantity]
[:tr :> 'first-child] (ef/content fruit)
[:tr :> 'last-child] (ef/content (str quantity)))
(em/deftemplate template1 "/templates/template1.html" [fruit-data]
[:#heading1] (ef/content "fruit")
[:thead :tr :> 'last-child] (ef/content "quantity")
[:tbody] (ef/content
(ns midje.cljs.basic)
(defn doubler [x] (* 2 x))
(defn world [] "world")
(defn hello []
(str "hello " (world)))
(ns goog-test.core
(:require [goog.testing.jsunit :as unit]
[goog.testing :as gt]
[goog.testing.TestCase :as tc])
(:use [midje.cljs.core :only [run-test]])
(:use-macros [midje.cljs.semi-sweet :only [expect fact run-tests]]
[midje.cljs.sweet :only [fact provided]]))
(defn world [] "world")
@ckirkendall
ckirkendall / sample.clj
Created May 2, 2012 14:03
multimethods clojure
;you have a map with a key :action
;this contains a known list of actions:
;:login, :register, :play, :logout
(defmulti appy-action :action)
;input looks like this
;{:action :login :username "test" :password "test"}
(defmethod apply-action :login [msg]
(let [username (:username msg)
@ckirkendall
ckirkendall / clojure-match.clj
Created June 15, 2012 02:26 — forked from bkyrlach/Expression.fs
Language Compare F#, Ocaml, Scala, Clojure, Ruby and Haskell - Simple AST example
(use '[clojure.core.match :only [match]])
(defn evaluate [env [sym x y]]
(match [sym]
['Number] x
['Add] (+ (evaluate env x) (evaluate env y))
['Multiply] (* (evaluate env x) (evaluate env y))
['Variable] (env x)))
(def environment {"a" 3, "b" 4, "c" 5})
@ckirkendall
ckirkendall / output.txt
Created June 18, 2012 02:11
J Program for creation of AST Add(Variable 'a',Multiply(Number 2, Variable 'b'))
┌───┬────────────┬──────────────────────────────────┐
│Add│┌────────┬─┐│┌────────┬──────────┬────────────┐│
│ ││Variable│a│││Multiply│┌──────┬─┐│┌────────┬─┐││
│ │└────────┴─┘││ ││Number│2│││Variable│b│││
│ │ ││ │└──────┴─┘│└────────┴─┘││
│ │ │└────────┴──────────┴────────────┘│
└───┴────────────┴──────────────────────────────────┘
@ckirkendall
ckirkendall / ExpressionTree.rb
Created June 18, 2012 15:18 — forked from jimweirich/Expression Tree
Another expression tree evaluator
Number = lambda { |env, num| num }
Variable = lambda { |env, var| env[var] }
Add = lambda { |env, a, b| evaluate(env, a) + evaluate(env, b) }
Multiply = lambda { |env, a, b| evaluate(env, a) * evaluate(env, b) }
def evaluate(env, exp)
op, *args = exp
op.(env, *args)
end
@ckirkendall
ckirkendall / Lambda.scala
Created June 18, 2012 16:09 — forked from bkyrlach/AST.cs
Lambda for Scala...
object Lambda extends App {
val number = (num: Int) => (env: Map[Symbol, Int]) => num
val variable = (id: Symbol) => (env: Map[Symbol, Int]) => env(id)
val add = (a: (Map[Symbol, Int]) => Int, b: (Map[Symbol, Int]) => Int ) => (env: Map[Symbol, Int]) => a(env) + b(env)
val multiply = (a: (Map[Symbol, Int]) => Int, b: (Map[Symbol, Int]) => Int ) => (env: Map[Symbol, Int]) => a(env) * b(env)
val environment = Map('a -> 1, 'b -> 2, 'c -> 3)
val expr_tree = add(variable('a), multiply(number(2), variable('b)))
println(expr_tree(environment))
@ckirkendall
ckirkendall / A-sum-higher-kinds.clj
Created June 19, 2012 22:12 — forked from bkyrlach/GenericVersion.scala
Polymorphism - Summation of Higher Kinds(Clojure, Ocaml, Haskell, Scala, Java).
(defrecord Tree [left elm right])
(defprotocol Monoid
(append [a b] )
(identity [a] ))
(defprotocol Foldable
(foldl [l f i])
(mfirst [l]))