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
;; | |
;; 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
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
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
$.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
; 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
(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
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
; minihttpd, tiny barebones clojure web server | |
; http://alan.xen.prgmr.com/ | |
(ns alandipert.minihttpd | |
(:use [clojure.contrib.duck-streams :only (reader writer read-lines spit to-byte-array)] | |
[clojure.contrib.str-utils :only (re-split str-join re-gsub)]) | |
(:import (java.net ServerSocket URLDecoder) | |
(java.io File))) | |
(def codes {200 "HTTP/1.0 200 OK" |
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
#!/usr/bin/env bash | |
# On Macs, you need to install growlnotify: http://growl.info/documentation/growlnotify.php | |
# and put it in your PATH somewhere. | |
function usage() { | |
echo "tailnote file [regex]" | |
echo | |
echo "Tail a file and show notifications using Growl or Mumbles for lines matching regex." | |
echo "If a regex is not provided, this will notify about all lines." | |
echo |