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
#!/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 |
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 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é"))) |
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
user=> (Base64/decodeBase64 "am9objphc2Rm") | |
java.lang.ClassCastException: java.lang.String cannot be cast to [B (NO_SOURCE_FILE: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
(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)) |
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 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)))) |
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- 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))) |
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
-- 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 */; |
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
>> x = false or :hooray | |
=> :hooray | |
>> x | |
=> false | |
>> |
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
#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]) { |
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
(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] |