Skip to content

Instantly share code, notes, and snippets.

@oskarth
oskarth / gist:3259872
Created Aug 4, 2012
Golang Concurrency
View gist:3259872
// Concurrency in Go
// ----------------------------------------------------------------
// several processes running at the same time
// dealing with lots of things at once (connections, computations)
// long live Murphy's^H^H^H^H^H^H^HMoore's law!
// Three things: execution, syncing/messaging and control flow
// 1) GOROUTINES
// ----------------------------------------------------------------
@oskarth
oskarth / gist:3469830
Created Aug 25, 2012
Intro to gradient descent, and why feature scaling leads to better convergence
View gist:3469830
ml gives computers ability to learn without being explicitly programmed.
# Linear Regression
linear regression is a simple model to find best for for data.
http://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Linear_regression.svg/400px-Linear_regression.svg.png
view above x and y axis as features, generalize to n-dimensional.
# Example
You have a data set with commute and sleep time, salary and happiness (1-10)
for the three features, commute, sleep and salary you want to predict happy
@oskarth
oskarth / gist:3469833
Created Aug 25, 2012
Intro to gradient descent, and why feature scaling leads to better convergence
View gist:3469833

Machine learning gives computers the ability to learn without being explicitly programmed.

Linear Regression

Linear regression is a simple model to find best fit for some data.

Example: You have a data set with commute time, sleep time, salary and happiness (1-10). For the three features - commute time, sleep time and salary - you want to predict happiness level.

Cost function and finding a good fit

How well does this line predict the data? Cost function (essentially sum of deltas between a line at a point and the real point) which we want to minimize. Once function converges we know we have a good fit. How do we find it? Gradient descent.

View gist:3920027
(ns chipper.core
(:use [clojure.contrib.combinatorics :only (selections)])
(:use [clojure.pprint :only (pprint)])
(:require [clojure.tools.macro :as macro]))
(defn bool-space
"Generates every possible boolean n-tuple."
[n]
(selections [0 1] n))
View core.clj
(defn- arrow?
"predicate that returns true if x is =>"
[x]
(and (symbol? x) (= (name x) "=>")))
(defn- split-body
"splits expression into two parts, one with input
pins and the other with => and outputs"
[body]
(split-with (complement arrow?) body))
View gates.clj
;; nand* is not defined in terms of other gates
;; read the source to find out how we deal with that
(defgate not* [in] => [out]
(nand* [in in] => [out]))
(defgate and* [a b] => [out]
(nand* [a b] => [w])
(not* [w] => [out]))
@oskarth
oskarth / long.clj
Created Nov 1, 2012
chipper.long-form.gates
View long.clj
(defn nand* [a b]
(let [[out] (if (= 2 (+ a b)) [0] [1])
out))
(defn not* [in]
(let [[out] (nand* in in)]
out))
(defn and* [a b]
(let [[w] (nand* a b)
@oskarth
oskarth / stacktrace
Created Dec 5, 2012
clojurescript reflex computed-observables
View stacktrace
;; using reflex clojurescript library
;; works
(def a (atom 0))
(def b (computed-observable (inc @a)))
(def c (computed-observable (dec @a)))
(def d (computed-observable (str @b)))
;; doesn't
;; maximum call stack exceeded
View gist:4242462
$ znc --version
ZNC 0.206+deb1 - http://znc.in
$ which znc
/usr/local/bin/znc
$ /usr/local/bin/znc --version
ZNC 1.1-git-20121207-8ffab186 - http://znc.in
IPv6: yes, SSL: yes, DNS: threads
@oskarth
oskarth / gist:4260501
Created Dec 11, 2012
minikanren break
View gist:4260501
#lang r5rs
;; chapter 3 minikanren
(define-syntax var
(syntax-rules ()
((_ x) (vector x))))
(define-syntax var? (syntax-rules ()
((_ x) (vector? x))))