Skip to content

Instantly share code, notes, and snippets.

@stuarthalloway
stuarthalloway / gist:2645453
Created May 9, 2012 15:22
Datomic queries against Clojure collections
;; Datomic example code
(use '[datomic.api :only (db q) :as d])
;; ?answer binds a scalar
(q '[:find ?answer :in ?answer]
42)
;; of course you can bind more than one of anything
(q '[:find ?last ?first :in ?last ?first]
"Doe" "John")
@sinc
sinc / gist:2409107
Created April 17, 2012 21:16
get rotation matrix from accelerometer
CMRotationMatrix rotationMatrixFromGravity(float x, float y, float z)
{
// The Z axis of our rotated frame is opposite gravity
vec3f_t zAxis = vec3f_normalize(vec3f_init(-x, -y, -z));
// The Y axis of our rotated frame is an arbitrary vector perpendicular to gravity
// Note that this convention will have problems as zAxis.x approaches +/-1 since the magnitude of
// [0, zAxis.z, -zAxis.y] will approach 0
vec3f_t yAxis = vec3f_normalize(vec3f_init(0, zAxis.z, -zAxis.y));
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@mdub
mdub / output.txt
Created March 21, 2012 02:34
Ruby lazy enumerable benchmark
$ ruby --version
ruby 2.0.0dev (2012-03-20 trunk 35094) [x86_64-darwin11.3.0]
$ ruby pipeline_bench.rb
IMPLEMENTATION take(10) take(100) take(1000) to_a
conventional (eager) 0.01416 0.01407 0.01422 0.01411
enumerating 0.00003 0.00007 0.00063 0.03140
lazing 0.00004 0.00011 0.00098 0.04759
ruby2 Enumerable#lazy 0.00004 0.00013 0.00112 0.05304
facets Enumerable#defer 0.00005 0.00018 0.00162 0.07108
@stuarthalloway
stuarthalloway / gist:1980351
Created March 5, 2012 18:56
frinj unit conversion running inside a Datomic datalog query
;; lein settings
(defproject foo "1.0.0-SNAPSHOT"
:description "Test App"
:dependencies [[com.datomic/datomic "0.1.2678"]
[frinj "0.1.2" :exclusions [org.clojure/clojure]]])
;; load libs
(use 'frinj.core 'frinj.calc)
(frinj-init!)
(use '[datomic.api :only (q db) :as d])
@rferraz
rferraz / cometd_client.clj
Created February 5, 2012 06:12
Clojure CometD client example
(ns test.cometd-client
(:import (org.cometd.bayeux.client ClientSessionChannel$MessageListener)
(org.cometd.client BayeuxClient BayeuxClient$State)
(org.cometd.client.transport ClientTransport LongPollingTransport)
(org.eclipse.jetty.client HttpClient)))
(def channel-name "/my-channel")
(def client-url "http://localhost:8080/cometd")
# Emulates the QuickCheck ?SOMETIMES macro.
module Sometimes
def run_with_retries(example_to_run, retries)
self.example.metadata[:retries] ||= retries
retries.times do |t|
self.example.metadata[:retried] = t + 1
self.example.instance_variable_set(:@exception, nil)
example_to_run.run
break unless self.example.exception
@hugoduncan
hugoduncan / gist:1690974
Created January 27, 2012 21:17
rvm crate
(ns pallet.crate.rvm
"Standard rvm install"
(:require
[pallet.crate.git :as git]
[pallet.action.conditional :as conditional]
[pallet.action.exec-script :as exec-script]
[pallet.action.package :as package]
[pallet.action.remote-file :as remote-file]
[pallet.action.user :as user]
[pallet.context :as context]
@hugoduncan
hugoduncan / gist:1666286
Created January 23, 2012 23:15
jekyll-mumamo with clojure-mode support
; highlight support for multiple languages
(defconst mumamo-highlight-tag-start-regex
(rx "{%"
(0+ space)
"highlight"
space
(submatch
(1+ (any "a-za-z")))
(0+ space)
"%}"
@semperos
semperos / clj->js.clj
Created January 22, 2012 19:43
ClojureScript to JavaScript (from mmcgrana)
(defn clj->js
"Recursively transforms ClojureScript maps into Javascript objects,
other ClojureScript colls into JavaScript arrays, and ClojureScript
keywords into JavaScript strings."
[x]
(cond
(string? x) x
(keyword? x) (name x)
(map? x) (.strobj (reduce (fn [m [k v]]
(assoc m (clj->js k) (clj->js v))) {} x))