This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed abstract class Expr { | |
def eval():Double | |
} | |
case class EValue(value:Double) extends Expr { | |
def eval():Double = value | |
} | |
case class ESum(a:List[Expr]) extends Expr { | |
def eval():Double = a.foldLeft(0.0)(_+_.eval) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '(org.jivesoftware.smack XMPPConnection)) | |
(use '[clojure.set :only (difference)]) | |
(defn connect [jid pass] | |
(doto (XMPPConnection. (last (.split jid "@"))) | |
.connect | |
(.login (first (.split jid "@")) pass))) | |
(defn ls [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Project euler problem 138 | |
; http://projecteuler.net/index.php?section=problems&id=138 | |
(use 'clojure.contrib.math) | |
(defn height [base leg] | |
(sqrt (- (expt leg 2) (expt (/ base 2) 2)))) | |
(defn base [leg height] | |
(* 2 (sqrt (- (expt leg 2) (expt height 2))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.golf.controller = [ | |
{ route: "/home/*/", | |
action: function(container, params) { | |
container.empty().append(new Component.MainPage(); | |
} | |
}, | |
{ route: function(uri) { return uri.indexOf('x') != -1; }, | |
action: function(container, params) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function LazySeq(fn, start) { | |
var last; | |
//functions to apply on realization | |
var maps = []; | |
//use lazy function definition | |
this.next = function() { | |
this.next = function() { | |
return last = fn(last); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redis' | |
class Set | |
def initialize(*elems) | |
if !defined? @@redis | |
@@redis = Redis.new | |
end | |
elems.each do |elem| | |
@@redis.set_add(object_id, elem) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; NS CHEATSHEET | |
;; | |
;; * :require makes functions available with a namespace prefix. | |
;; | |
;; * :use makes functions available without a namespace prefix | |
;; (i.e., refers functions to the current namespace). | |
;; | |
;; * :import refers Java classes to the current namespace. | |
;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn- get-chars | |
"gets the next char(s) in the sequence" | |
[s offset] | |
(if (>= offset (count s)) | |
(let [div-val (dec (int (/ offset (count s)))) | |
mod-val (mod offset (count s))] | |
(apply str (get-chars s div-val) (get-chars s mod-val))) | |
(subs s offset (inc offset)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define ID_SIZE 6 | |
// this is the array of authorized key strings that | |
// reader input is checked against | |
char *authorized_ids[] = { | |
"000013579EF3", | |
"\0" | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def let(binds, &body) | |
eval("proc{|#{binds.keys.join(',')}| body }").call(*binds.values).call | |
end | |
let(:a => 10, :b => 20) { | |
puts a,b | |
} |