This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'optparse' | |
require 'zip' | |
require 'fileutils' | |
# parse command line arguments | |
options = {} | |
OptionParser.new do |opt| | |
opt.on('-f FROM_ENC') {|o| options[:from_enc] = o} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Kalman filtering | |
# Prediction: | |
# x_pre[k] = A*x[k-1] + B*u[k] | |
# P_pre[k] = A*P[k-1]*A' + Q | |
# Measurement update: | |
# K[k] = P_pre[k]*H'*(H*P_pre[k]*H'+R)**(-1) | |
# x[k] = x_pre[k] + K[k]*(z[k]-H*x_pre[k]) | |
# P[k] = (I-K[k]*H)*P_pre[k] | |
# | |
# Simplified with A=H=1, B=0, Q=0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import argparse | |
import hashlib | |
import itertools | |
import os | |
import multiprocessing as mp | |
import sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import itertools | |
import hashlib | |
# generate a rainbow table for HKID | |
# 2017-02-11 | |
def checkdigit(a, i, j, k, l, m, n): | |
numeric = [ord(a) - 65 + 1, int(i), int(j), int(k), int(l), int(m), int(n)] | |
weight = range(8,1,-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
import datetime | |
import os | |
import subprocess | |
import time | |
import urlparse | |
from StringIO import StringIO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Knuth, Dancing Link, 2000 | |
* | |
* This program solve the covering set problem using the DLX algorithm in the | |
* abovementioned paper. | |
*/ | |
#include <iostream> | |
#include <vector> | |
#include <string> | |
#include <memory> // for shared_ptr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
generate n random walks from 0 to T with N steps | |
Returns: | |
t (range) of time from 0 to T with N steps | |
W (nxN array) of random walks | |
""" | |
function rwalks(T,N,n) | |
dt = T/N | |
dW = sqrt(dt)*randn(n,N) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2D multivariate normal | |
# with covariance matrix [3 2; 2 5], i.e. Var(x)=3, Var(y)=5, Cov(x,y)=2 | |
# Break down covariacne matrix with Cholesky decomposition and multiply with iid std normal random numbers | |
Sigma = [4 9; 9 25] | |
S = chol(Sigma) # upper triangular part, i.e. S' * S == Sigma | |
iidnorm = randn(2,1000) | |
rv = S' * iidnorm # 2x1000 matrix of 1000 random number pairs conforms to the covariance matrix Sigma | |
# Plot in 2D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
# Expose argparser into global scope | |
_parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) | |
_subcmds = _parser.add_subparsers( | |
title="Commands", | |
description="Available actions", | |
dest="subcmd") | |
# Subcommand argparse decorator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stalinsort(unsorted): | |
"""Stalin sort: O(n) sort algorithm that iterate down a | |
list of elements, any element which is out of order is | |
eliminated. | |
https://www.facebook.com/ProgrammersCreateLife/photos/a.241809332534619/1934139766634892/?type=1&theater | |
Args: | |
unsorted: Iterable of elements that support >= operator | |
Returns: | |
A list of subset of the input |
OlderNewer