Skip to content

Instantly share code, notes, and snippets.

View siddMahen's full-sized avatar

Siddharth Mahendraker siddMahen

  • Toronto, Canada
View GitHub Profile
var alg = require("algorithms"),
sort = alg.mergeSort;
/*
* Huffman coding.
*
* @api public
*/
var huffman = function(alphabet){
import Base.open
import Base.close
import Base.readlines
@vectorize_1arg String open
@vectorize_1arg IOStream close
@vectorize_1arg IOStream readlines
# map a dict into an array
function dict_map(f::Function, d::Dict)
importall Base
immutable ModInt{N} <: Integer
val::Int
ModInt(x) = new(mod(x,N))
end
-{N}(x::ModInt{N}) = ModInt{N}(-x.val)
+{N}(x::ModInt{N}, y::ModInt{N}) = ModInt{N}(x.val + y.val)
-{N}(x::ModInt{N}, y::ModInt{N}) = ModInt{N}(x.val - y.val)
@siddMahen
siddMahen / ordered.jl
Created June 20, 2014 19:39
Turns a literal dictionary into an array of tuples.
macro ordered(ex::Expr)
if ex.head == :dict
ex.head = :vcat
ex.args = map(ex.args) do x
:(($(esc(x.args[1])),$(esc(x.args[2]))))
end
elseif ex.head == :typed_dict
ex.head = :vcat
shift!(ex.args)
ex.args = map(ex.args) do x
#!/bin/bash
for i in {3..229}
do
curl -s "http://twssstories.com/node?page=$i" | perl -n -e '/"([^"]*)" TWSS/ && print "$1\n"' >> twss_test.txt
done
cat eng-ca_web_2002_100K-sentences.txt | perl -n -e '/^[0-9]+\s+([A-Z].*\.)$/ && print "$1\n"' | grep " I " >> normal.txt
cat eng-uk_web_2002_100K-sentences.txt | perl -n -e '/^[0-9]+\s+([A-Z].*\.)$/ && print "$1\n"' | grep " I " >> normal.txt
function m(word::String)
str = split(word, "")
seeking = true
sawvowel = false
sawconsonant = false
count = 0
for w in str
if seeking && isvowel(w)
seeking = false
@siddMahen
siddMahen / min-edit-distance.jl
Last active August 29, 2015 14:02
Dynamic programming minimum edit distance algorithm, implemented in Julia.
function min_edit_distance(a :: String, b :: String)
m = length(a)
n = length(b)
D = Array(Uint, m + 1, n + 1)
F = Array(Uint, m + 1, n + 1)
for i = 1:m + 1, j = 1:n + 1
D[i, 1] = i - 1
D[1, j] = j - 1
@siddMahen
siddMahen / downloads.md
Created June 11, 2014 20:01
Useful software to have on a new machine.
@siddMahen
siddMahen / gaussian.html
Last active August 29, 2015 14:01
Naive Gaussian distributions in Javascript.
<!DOCTYPE html>
<html>
<head>
<title>Gaussian Distributions</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style>
.chart div {
background-color: steelblue;
font: 10px sans-serif;
border: 2px solid white;
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
navigator.webkitGetUserMedia({audio:true}, function(s){
window.AudioContext = window.AudioContext || window.webkitAudioContext;