Skip to content

Instantly share code, notes, and snippets.

(fn [sos]
(letfn [
(combine [x y]
(let [diff [nil (.toUpperCase (str (clojure.set/difference x y)))] ]
(conj (clojure.set/intersection x y) diff)))
(remove-dontcares [minterms] (set (remove vector? minterms)))
(get-off-by-ones [all-minterms [current-key current-vals]]
(let [
off-by-one
(map #(combine current-key %)
@jabley
jabley / video-events.js
Created January 27, 2012 10:58
Script to show video events in HTML5
// Investigating http://www.w3.org/2010/05/video/mediaevents.html
// Firefox creates pause and play events when seeking / seeked on a playing video, Chrome does not.
// Execute this script in Firebug console or similar to capture events
var script = document.createElement("script");
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
document.getElementsByTagName("head")[0].appendChild(script);
$("#video").bind("play", function() {console.log("play " + new Date()); })
$("#video").bind("pause", function() {console.log("pause " + new Date()); })
@jabley
jabley / gist:1228867
Created September 20, 2011 11:05 — forked from marick/gist:1228842
(ns scratch.core
(:use midje.sweet
[clojure.set :only [union intersection difference]]
))
(def east [1 0])
(def north [0 1])
(def west [-1 0])
(def south [0 -1])
@jabley
jabley / gist:1226883
Created September 19, 2011 16:24 — forked from marick/gist:1226882
(ns scratch.core
(:use midje.sweet
[clojure.set :only [union intersection]]
))
(unfinished booking-transaction bookings)
(defn empty-history []
[ [] ])
@jabley
jabley / gist:1226431
Created September 19, 2011 12:48 — forked from marick/gist:1226430
(ns scratch.core
(:use midje.sweet
[clojure.set :only [union intersection]]
:reload))
(unfinished newborns)
(defn survivable? [cell living-cells])
;; (fact "A cell is survivable if 2 or 3 of its neighbors are alive"
@jabley
jabley / partial_application.rb
Created September 19, 2011 06:08 — forked from headius/partial_application.rb
Partial application that works on all Ruby implementations
class Object
def _(name, *partial_args)
Proc.new do |*new_args|
send name, *partial_args.map {|arg| arg == :_ ? new_args.shift : arg}
end
end
end
# Practical examples:
[1,2,3].each &_(:puts, :_)
@jabley
jabley / gist:748880
Created December 20, 2010 19:40 — forked from tfheen/gist:748877
server {
listen 443; ## listen for ipv4
listen [::]:443 default ssl ipv6only=on; ## listen for ipv6
ssl on;
ssl_certificate /etc/ssl/certs/www.varnish-cache.org-http.pem;
ssl_certificate_key /etc/ssl/private/www.varnish-cache.org-http.pem;
server_name www.varnish-cache.org;
access_log /var/log/nginx/localhost.access.log;
This example shows how to setup an environment running Rails 3 beta 3 under 1.9.2-head with a 'rails3' gem set.
∴ rvm update --head
# ((Open a new shell)) or do 'rvm reload'
# If you do not already have the ruby interpreter installed, install it:
∴ rvm install 1.9.2-head
# Switch to 1.9.2-head and gemset rails3, create if it doesn't exist.
∴ rvm --create use 1.9.2-head@rails3
/* Use this to cause a function to fire no more than once every 'ms' milliseconds.
For example, an expensive mousemove handler:
$('body').mouseover(ratelimit(function(ev) {
// ...
}, 250));
*/
function ratelimit(fn, ms) {
var last = (new Date()).getTime();
@jabley
jabley / sort.scala
Created November 4, 2009 16:14 — forked from Lytol/selection_sort.scala
sort.scala
// Inmperative version
//
def selectionSort(list: Array[Int]): Unit {
def swap(list: Array[Int], i: Int, j: Int) {
var tmp = list(i)
list(i) = list(j)
list(j) = tmp
}
var i = 0