Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
CLASSPATH=src:$CLJ_HOME/clojure.jar:$CLJ_CONTRIB_HOME/clojure-contrib.jar
for f in lib/*.jar; do
CLASSPATH=$CLASSPATH:$f
done
rlwrap java -cp $CLASSPATH clojure.lang.Repl
(defn with-json [handler]
(fn [request]
(json/encode-to-str (handler request))))
(defn with-requires-https [handler]
(fn [request]
(if (= :https (:scheme request))
(handler request)
"No way José")))
user=> (Base64/decodeBase64 "am9objphc2Rm")
java.lang.ClassCastException: java.lang.String cannot be cast to [B (NO_SOURCE_FILE:0)
(defn unbean [m]
"Tries to recreate a simple JavaBean object from map m"
(let [obj (.newInstance (:class m))]
(doseq [[k v] (dissoc m :class)]
(try
(clojure.lang.Reflector/setInstanceField obj (name k) v)
(catch Exception _ nil)))
obj))
(ns atomic-spit
(:use clojure.contrib.duck-streams))
(defn atomic-spit [path data]
(let [temp (File/createTempFile "spit" nil)]
(spit temp data)
(.renameTo temp (File. path))))
(defn- save-agent [_ path data]
(atomic-spit path data)
(println (.getTime (Date.)) "wrote" path))
(defn saved-ref [path default]
"Returns a ref backed by the file at path, with the default value if path could not be loaded"
(let [value (read-string (clojure.contrib.duck-streams/slurp* path))
r (ref (or value default))
a (agent nil)]
(add-watch r a (fn [_ _ _ new-val] (send-off a save-agent path new-val)))
-- Sequel Pro dump
-- Version 1630
-- http://code.google.com/p/sequel-pro
--
-- Host: 127.0.0.1 (MySQL 5.1.42)
-- Database: ls
-- Generation Time: 2010-02-03 16:30:19 -0500
-- ************************************************************
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
>> x = false or :hooray
=> :hooray
>> x
=> false
>>
@jcromartie
jcromartie / NoNulls.m
Created February 19, 2010 17:57
Traverse dictionaries and arrays omitting NSNull values
#define OmitNullMethod @selector(valueOmittingNullValues)
#define OmitNullRecursively(x) ([x respondsToSelector:OmitNullMethod] ? [x performSelector:OmitNullMethod] : x)
@implementation NSDictionary (NoNulls)
- (NSDictionary *)valueOmittingNullValues {
NSMutableDictionary *newDict = [NSMutableDictionary dictionaryWithCapacity:[self count]];
for (id key in [self allKeys]) {
id obj = [self objectForKey:key];
if (obj != [NSNull null]) {
(defmodel message
:coll :messages
:fields {:msg [non-empty-str (partial truncate-str 140)]
:points [int :default 0]
:user_id [to-id required]
:venue_id [to-id]
:created [date :default current-date]
:updated [current-date]
:fb [str]
:tw [str]