Skip to content

Instantly share code, notes, and snippets.

@lynaghk
lynaghk / gist:790631
Created January 21, 2011 23:25
R k-nearest neighbors example
#I'm using two non-standard packages; one for nearest neighbors (FNN) and one for doing split-combine-apply (think map reduce) type operations.
#you'll have to run this: install.packages(c('FNN', 'plyr'))
#you can also checkout documentation in R using the question mark; run this: ?knn
library(FNN)
library(plyr)
#Here are some random points on the plane to show you the interface
neartop = ldply(1:50, function(i){
c( x = rnorm(1)
, y = 1 + rnorm(1, sd=0.5))
Things I don't particularly like about Devin Chalmers:
1. He doesn't write any tests before implementing John Conway's Game of Life.
2. He asks for whiskey with lots of different, non-whiskey things mixed in.
3. He put a second top tube on his bicycle and then stopped riding it.
4. Looks better in a pair of brass goggles than I do.
@lynaghk
lynaghk / gist:823847
Created February 12, 2011 16:07
compojure resources problem between 0.5.2 and 0.6.0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;/login.html (a static resource) does not work in [compojure "0.6.0-RC4"]
;;however, the simple GET works fine
;; 2011-02-12 08:03:25.840:WARN::/login.html
;; java.lang.NullPointerException
;; at ring.middleware.session$wrap_session$fn__3069.invoke(session.clj:47)
;; at ring.middleware.cookies$wrap_cookies$fn__3009.invoke(cookies.clj:132)
;; at clojure.lang.Var.invoke(Var.java:365)
;; at ring.adapter.jetty$proxy_handler$fn__2063.invoke(jetty.clj:16)
;;
\documentclass[a4paper,11pt,leqno,article,oneside]{memoir}
\usepackage[leqno]{amsmath}
\usepackage{amsfonts}
\begin{document}
\title{Test Document}
\chapter{Clustering}
@lynaghk
lynaghk / gist:878657
Created March 20, 2011 20:40
Pubtex JSONP
<!DOCTYPE html>
<head>
<meta charset='utf-8'>
</head>
<body>
<h1>Original Page content</h1>
<p>blah blah blah</p>
<div id='my_pubtex'></div>
</body>
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js'></script>
@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]]