Skip to content

Instantly share code, notes, and snippets.

@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 }
@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 user@server.com 'cat >> .ssh/authorized_keys'
@teropa
teropa / resources.md
Last active December 4, 2020 05:42
Clojure Resources

Tutorials

@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
});
});
@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)))]
@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))
@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 / 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)))
@fogus
fogus / latency.txt
Created June 7, 2012 17:41 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@jboner
jboner / latency.txt
Last active July 29, 2024 12:48
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD