Skip to content

Instantly share code, notes, and snippets.

View jxnl's full-sized avatar

Jason Liu jxnl

View GitHub Profile

Contract Killer

The popular open-source contract for web designers and developers by Stuff & Nonsense

  • Originally published: 23/12/2008
  • Revised date: 15/12/2013
  • Original post

@jxnl
jxnl / Three_Point_Newton–Cotes_formula.py
Last active August 29, 2015 14:00
A staple of scientific data analysis and engineering this is my implementation of Simpson's Rule as the sum on a list comprehension. It takes advantage of compositing Midpoint and Trapezoid rules.
def simpson(a, b, f, N):
return (1.0 / 3.0) * (2 * (((b - a) / N) * \
sum(f(v) for v in [i * ((b - a) / (2. * N))\
for i in range(2 * N + 1)][1:2 * N + 1:2]))\
+ (((b - a) / N) * ((f(a) + f(b)) / 2.0 + sum\
(f(v * ((b - a) / N) + a) for v in xrange(1, N
)))))
# int_0^1 x^2 + 2 + 2 = 1/3
print simpson(0,1,lambda x:x**2+x*2+2, 100)
import java.util.Random;
/**
* Implements the Epsilon Greedy Bandit algorithm for finding
* optimal probabilities of success given k binomial distributions.
*/
public class EpsilonGreedyBandit {
private final double [] SAMPLE_ARMS;
private final float GREEDYNESS;
private int[] numberOfSuccesses;
// http://app.toronto.ca/DevelopmentApplications/dwr/test/MapSearchService
var reply0 = function(data)
{
if (data != null && typeof data == 'object') console.log(dwr.util.toDescriptiveString(data, 100));
else dwr.util.setValue('d0', dwr.util.toDescriptiveString(data, 1));
}
function keep_alive() {
http_request = new XMLHttpRequest();
@jxnl
jxnl / East Toronto
Last active August 29, 2015 14:01
When I attended the Toronto Opendata conference, the speaker said that they had a lot of trouble getting all the data from the [Toronto Development Projects](http://app.toronto.ca/DevelopmentApplications/mapSearchSetup.do?action=init) page out to a computer readable format. Needless to say, I ended up scraping the thing with some javascript and …
[
{
communityInfo:null,
folderDescription:"Proposed Canada Post Depot building with a gross floor area of 1858.45 sq. m. (20,005 sq.ft.). The facility will provide for final mail sorting and destination delivery, with ancillary offices, employee locker rooms, etc.. A total of 205 parking parking spaces are proposed to supply both employee parking and fleet parking for the postal delivery vans (5-ton vehicles only). This is a new Canada Post prototype facility where the delivery van drivers will also now have traditional mail routes to provide actual door-to-door mail delivery as well. Building coverage proposed is approximately 18.5%, with approximately 9.4% of the site to be landscaped. The building is proposed to be LEED certified and energy efficient. NOAC issued Aug. 6, 2013, signed by Greg Lintern, Director, Community Planning.",
folderRevision:"37",
folderRsn:3250063,
folderSection:"ESC",
folderSequence:"278253",
folderType:"SA",
folderTypeDesc:"Site Plan
  1. General Background and Overview
@jxnl
jxnl / naive_trainer.py
Last active August 29, 2015 14:03
!!!
"""
Author: Jason Liu
"""
from __future__ import division
from collections import defaultdict
from nltk.corpus import stopwords
from string import maketrans, punctuation
from itertools import imap
@jxnl
jxnl / sample.py
Last active August 29, 2015 14:03
Uniformly Sample k elements from file or stream of arbitrary size.
"""
This is a effective random uniform sampling module known as
Reservoir Sampling which uniformly samples a subset of k elements from a larger
'reservoir' of size N where N is usually unknown or very large.
This command line tool and be piped a stream or inputed a file.
Author: Jason Liu
Date: May 24th, 2014
### MATPLOTLIBRC FORMAT
# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
# there, please note that it will be overridden in your next install.
# If you want to keep a permanent local copy that will not be
# over-written, place it in HOME/.matplotlib/matplotlibrc (unix/linux
# like systems) and C:\Documents and Settings\yourname\.matplotlib
# (win32 systems).
def qsort(xs):
if xs == []:
return xs
else:
fst, *rst = xs
sm = qsort(list((x for x in rst if x <= fst)))
lg = qsort(list((x for x in rst if x > fst)))
return sm + [fst] + lg