Skip to content

Instantly share code, notes, and snippets.

@lynaghk
lynaghk / Main.mirah
Created May 2, 2011 13:57
Mirah + Proguard
package "com.pgtest"
class Rubyisms
macro def attr_reader(name)
quote do
def `name`
@`name`
end
end
end
@lynaghk
lynaghk / create_db.rb
Created June 17, 2011 17:39
Create UK University Stats Database
#!/usr/bin/env ruby
#
# Copyright Keming Labs 2011
# But you can use it under the MIT license. Yay!
# See our visualization of these data here:
#
# http://keminglabs.com/ukuni/
#
# This script imports data from UCAS
#
@lynaghk
lynaghk / gist:1062939
Created July 4, 2011 05:28
R + Sqlite example
# Run this first:
#
# install.packages(c('RSQLite.extfuns', 'ggplot2', 'maps'))
#
library(RSQLite)
library(ggplot2)
library(RSQLite.extfuns)
db = dbConnect(
dbDriver("SQLite")
@lynaghk
lynaghk / README.markdown
Created August 10, 2011 17:11
OpenVBX troubles

Setup PHP

apt-get install mysql-server php5-cgi php5-mysql php5-curl php5-cli

cp default-php-fastcgi /etc/default/php-fastcgi cp php-fastcgi /etc/init.d/

update-rc.d php-fastcgi defaults

@lynaghk
lynaghk / gist:1141054
Created August 11, 2011 23:21
Clojure sequentials & maps into JavaScript arrays and objects
(defn jsArr
"Recursively converts a sequential object into a JavaScript array"
[seq]
(.array (vec (map #(if (sequential? %) (jsArr %) %)
seq))))
(defn jsObj
"Convert a clojure map into a JavaScript object"
[obj]
(.strobj (into {} (map (fn [[k v]]
@lynaghk
lynaghk / gist:1334086
Created November 2, 2011 16:20
Counting occurrences of items in a collection
;;Three ways to count the number of occurrences in a collection
;; ("orange" "bottle" "coke" "bottle") => [("bottle" "coke" "orange") (2 1 1)]
(let [c '("orange" "bottle" "coke" "bottle")]
(let [counts (reduce #(conj %1 (hash-map %2 (inc (get %1 %2 0))))
{} c)]
[(keys counts)
(vals counts)])
@lynaghk
lynaghk / gist:1334952
Created November 2, 2011 21:17
<canvas> gradient generator
# print to console for debugging
p = (x) ->
console.log x
x
# generate HSL object from normalized arguments
hsl = (hue, saturation, lightness) ->
h: hue
s: saturation
l: lightness
$("#marketList tbody.yui-dt-data")
.find('tr')
.map(function(_,row){
var $r = $(row);
var data = {
"name": $r.find(".yui-dt-col-market").text()
, "sell": parseFloat($r.find(".yui-dt-col-sell").text())
, "buy": parseFloat($r.find(".yui-dt-col-buy").text())
};
return data;
class Cl.errors.Error
description: -> "An error has occurred in Cassowary Coffee"
toString: -> @description()
class Cl.errors.ConstraintNotFound extends Cl.errors.Error
description: -> "Tried to remove a constraint never added to the tableau"
class Cl.errors.NonlinearExpression extends Cl.errors.Error
description: -> "The resulting expression would be nonlinear"
@lynaghk
lynaghk / gist:1551222
Created January 2, 2012 16:06
ClojureScript multimethod namespace reference problem
;;ClojureScript compiler 329708 (2011.12.14)
;;Based on RangeNum protocol by Tassilo Horn:
;; http://groups.google.com/group/clojure/browse_thread/thread/f3192b351b0ab2b4/ec6c106dfdcf0cf9?lnk=gst&q=ranged#msg_ed6de8b7a5cabf41
(ns c2.main
(:refer-clojure :exclude [+])
(:use-macros [c2.util :only [typeof]]))
(defprotocol RangeNumProtocol