Skip to content

Instantly share code, notes, and snippets.

(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))))
;;
;; 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.
;;
require 'redis'
class Set
def initialize(*elems)
if !defined? @@redis
@@redis = Redis.new
end
elems.each do |elem|
@@redis.set_add(object_id, elem)
@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);
$.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) {
; 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)))))
@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 []
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)
; 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"
#!/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