Skip to content

Instantly share code, notes, and snippets.

@fogus
fogus / lisp_ch1.clj
Created August 15, 2012 02:13
Chapter 1 from Lisp in Small Pieces
(ns lisp-ch1)
(def self-evaluating?
(some-fn number? string? char?
true? false? vector?))
(defn -atom? [s]
(or (self-evaluating? s)
(symbol? s)))
@samaaron
samaaron / pg.clj
Created August 23, 2012 10:22
How to suck an entire postgres db into Clojure datastructures in memory
(ns ormclj.pg
(:require [clojure.java.jdbc :as sql]))
(defn pg-db
[hostname port db-name user passwd]
{:classname "org.postgresql.Driver"
:subprotocol "postgresql"
:subname (str "//" hostname ":" port "/" db-name)
:user user
:password passwd})
@fogus
fogus / gist:3687940
Created September 9, 2012 23:36 — forked from Chouser/gist:3687532
Lazy seq as event subscription mechanism
;; This defines the event stream, in this case just a series of numbers,
;; a new one produced each second
(defn timer []
(lazy-seq
(do
(Thread/sleep 1000)
(cons (System/nanoTime) (timer)))))
;; We can see some events (this takes a couple seconds to complete):
(take 3 (timer))
@richhickey
richhickey / thread.clj
Created October 13, 2012 17:43
new thread macros draft
(defmacro test->
"Takes an expression and a set of test/form pairs. Threads expr (via ->)
through each form for which the corresponding test expression (not threaded) is true."
[expr
& clauses]
(assert (even? (count clauses)))
(let [g (gensym)
pstep (fn [[test step]] `(if ~test (-> ~g ~step) ~g))]
`(let [~g ~expr
~@(interleave (repeat g) (map pstep (partition 2 clauses)))]
@daniel-beard
daniel-beard / gist:4516490
Created January 12, 2013 06:56
Background / Foreground async dispatches ios objective-c
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//background processing goes here
dispatch_async(dispatch_get_main_queue(), ^{
//update UI here
});
});
@teropa
teropa / resources.md
Last active December 4, 2020 05:42
Clojure Resources

Tutorials

@orendon
orendon / add_ssh_key_deploy.sh
Created April 30, 2014 19:09
add ssh key to remote server authorized_keys
# add ssh key on remote server
cat ~/.ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'
@marklarr
marklarr / swiftRegex.swift
Created June 3, 2014 06:53
Ruby-esque regex in Swift
// Regex
import Foundation
operator infix =~ {}
@infix func =~ (str: String, pattern: String) -> Bool {
var error: NSError?
let regex = NSRegularExpression.regularExpressionWithPattern(pattern, options: nil, error: &error)
if (error) { return false }