Skip to content

Instantly share code, notes, and snippets.

@retnuh
retnuh / TokenFSM.scala
Last active July 5, 2016 15:24
TokenFSM - a simple token-based FSM for efficient token matching from a lexicon, etc.
package tokenfsm
import scala.annotation.tailrec
import scala.collection.immutable.SortedSet
/**
* Created by retnuh on 04/07/2016.
*/
object TokenFSM {
@retnuh
retnuh / bad.clj
Last active April 17, 2016 01:45
A test case that makes enlive go boom!
(ns bad
(:import (java.io StringReader))
(:require [clojure.string :as string]
[net.cgrand.enlive-html :as enlive]))
(defn html-to-text
[html]
(let [text
(-> html
(StringReader.)
@retnuh
retnuh / dentists-dublin-google.html
Created May 3, 2013 10:02
dentists-dublin-google.html attachment for mochiweb bug report
<!doctype html> <head> <title>dentists dublin - Google Search</title> <script>window.google={kEI:"sHsdTq30NILDhAfTyOTCBw",kEXPI:"17311,27731,28505,28936,30316,30869,31116,31215,31259,31303,31396,31405",kCSI:{e:"17311,27731,28505,28936,30316,30869,31116,31215,31259,31303,31396,31405",ei:"sHsdTq30NILDhAfTyOTCBw",expi:"17311,27731,28505,28936,30316,30869,31116,31215,31259,31303,31396,31405"},authuser:0,ml:function(){},pageState:"#",kHL:"en",time:function(){return(new Date).getTime()},
log:function(c,d,b){var a=new Image,e=google,g=e.lc,f=e.li;a.onerror=(a.onload=(a.onabort=function(){delete g[f]}));g[f]=a;b=b||"/gen_204?atyp=i&ct="+c+"&cad="+d+"&zx="+google.time();a.src=b;e.li=f+1},lc:[],li:0,j:{en:0,l:function(){google.fl=true},e:function(){google.fl=true},b:location.hash&&location.hash!="#",bv:20,pm:"i",
pl:[],mc:0,sc:0.5,u:"a05e4fab"},Toolbelt:{}};(function(){var c=google.j;window.onpopstate=function(){c.psc=1};for(var d=0,b;b=["ad",
"bc","is","p","pa","ac","pc","pah","ph","sa","slp","spf","xx","zc","z
@retnuh
retnuh / uf.clj
Last active December 12, 2015 09:09
Union Find algorithm in Clojure using the state-m Monad for keeping track of state. Monad code found at https://github.com/clojure/algo.monads Good explanation of Monads and state monad http://www.intensivesystems.net/tutorials/monads_101.html
(ns euler.algo.uf
(:use clojure.algo.monads))
(with-monad state-m
(defn get-or-add [key]
(fn [s]
(if-let [v (get s key)]
[v s]
[[key 1] (assoc s key [key 1])])))
@retnuh
retnuh / web_send.js
Created June 27, 2012 12:00
tweaked web_send.js etc.
/*
* Copyright 2007-2009 Tyler Close under the terms of the MIT X license found
* at http://www.opensource.org/licenses/mit-license.html
*
* web_send.js version: 2009-06-06
*
* This library doesn't actually pass the ADsafe verifier, but rather is
* designed to provide a controlled interface to the network, that can be
* loaded as an ADsafe library. Clients of this library have permission to send
* requests to the window target, and any target returned in a request
@retnuh
retnuh / gradientDescentMulti.m
Created October 25, 2011 12:56
Machine Learning MultiVar Gradient Descent
function [theta, J_history] = gradientDescentMulti(X, y, theta, alpha, num_iters)
%GRADIENTDESCENTMULTI Performs gradient descent to learn theta
% theta = GRADIENTDESCENTMULTI(x, y, theta, alpha, num_iters) updates theta by
% taking num_iters gradient steps with learning rate alpha
% Initialize some useful values
m = length(y); % number of training examples
n = size(X, 2); % number of features (+ 1)
J_history = zeros(num_iters, 1);