Skip to content

Instantly share code, notes, and snippets.

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)
@alandipert
alandipert / xmpp.clj
Created October 29, 2009 12:16 — forked from hiredman/xmpp.clj
(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 []
; 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)))))
$.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) {
@alandipert
alandipert / util.js
Created January 14, 2010 07:00 — forked from anonymous/util.js
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);
require 'redis'
class Set
def initialize(*elems)
if !defined? @@redis
@@redis = Redis.new
end
elems.each do |elem|
@@redis.set_add(object_id, elem)
;;
;; 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.
;;
(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))))
@alandipert
alandipert / char.c
Created January 31, 2010 22:00 — forked from anonymous/char.c
#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"
};
@alandipert
alandipert / let.rb
Created February 2, 2010 05:55 — forked from anonymous/let.rb
def let(binds, &body)
eval("proc{|#{binds.keys.join(',')}| body }").call(*binds.values).call
end
let(:a => 10, :b => 20) {
puts a,b
}