Skip to content

Instantly share code, notes, and snippets.

View nybbles's full-sized avatar

Nimalan Mahendran nybbles

View GitHub Profile
@nybbles
nybbles / students.lua
Created December 17, 2015 01:46
Multivariate student-t distribution in Lua/Torch
#!/usr/bin/env th
local distrib = require 'distributions'
local cephes = require 'cephes'
local function logp_studentT(x, mu, chol_sigma, v)
local lgam = cephes.lgam
local d = mu:size(1)
local inv_sigma = torch.potri(chol_sigma)
@nybbles
nybbles / gist:2802052
Created May 27, 2012 03:33
Keyword parameters in Clojure, by Rich Hickey
;; From https://groups.google.com/forum/?fromgroups#!msg/clojure/CqV6smX3R0o/-FRxB8pTu1EJ
(defn keyword? [x]
(instance? clojure.lang.Keyword x))
(defmacro defnk [sym args & body]
(let [pos-keys (split-with (complement keyword?) args)
ps (pos-keys 0)
ks (apply array-map (pos-keys 1))
gkeys (gensym "gkeys__")
# This is just pseudocode, haven't tested it.
s = [];
s.push((root, False));
while !s.empty():
node, seen = s.pop();
if !seen:
if node.right:
s.push((node.right, False))
@nybbles
nybbles / gist:1985429
Created March 6, 2012 10:02
Why does this hang?
(ns blah.core
(:require [clojure.string :as string])
(:use lamina.core)
(:use [aleph.http :as http]
[aleph.formats :as formats]))
(defn get-content-channel [url]
(run-pipeline
url
#(http/http-request {:method :get :url %1})
@nybbles
nybbles / no_starvation.py
Created December 6, 2011 07:53
Solution to readers-writer problem
# Implement this!
# Look here for answer: http://www.rfc1149.net/blog/2011/01/07/the-third-readers-writers-problem/