Skip to content

Instantly share code, notes, and snippets.

View indiejoseph's full-sized avatar
🏠
Working from home

Joseph Cheng indiejoseph

🏠
Working from home
View GitHub Profile
@wkschwartz
wkschwartz / profiling.py
Created April 24, 2013 21:55
Timing/profiling tests on different branches of https://github.com/wkschwartz/algorithms2
from math import sqrt
def ttest(x1, x2):
"Student's t-test for unpaired, equal variance, equal size samples."
if len(x1) != len(x2):
raise ValueError('unequal sample sizes')
mx1 = sum(x1) / len(x1)
mx2 = sum(x2) / len(x2)
s2x1 = sum((xi - mx1)**2 for xi in x1) / (len(x1) - 1)
s2x2 = sum((xi - mx2)**2 for xi in x2) / (len(x2) - 1)
@larsmans
larsmans / kmeans.py
Created February 14, 2013 13:38
k-means clustering in pure Python
#!/usr/bin/python
#
# K-means clustering using Lloyd's algorithm in pure Python.
# Written by Lars Buitinck. This code is in the public domain.
#
# The main program runs the clustering algorithm on a bunch of text documents
# specified as command-line arguments. These documents are first converted to
# sparse vectors, represented as lists of (index, value) pairs.
from collections import defaultdict
@kTmnh
kTmnh / javascript_techniques.js
Last active May 13, 2016 09:26
JavaScript techniques including bitwise operator replacement techniques, shortcuts, etc.
var PI = Math.PI;
//Faster replacement for Math object methods.
Math.round(PI) === PI + (PI < 0 ? -0.5 : +0.5) >> 0;
Math.ceil(PI) === PI + (PI < 0 ? -1 : 0) >> 0;
Math.floor(PI) === PI + (PI < 0 ? -1 : 0) >> 0;
//Conditional operator is faster than Math object methods.
Math.max(a, b) === (a > b) ? a : b;
Math.min(a, b) === (a < b) ? a : b;
@ykhs
ykhs / _linear-gradient.scss
Created September 10, 2012 11:55
linear-gradient Sass Mixin
@mixin linear-gradient($angle, $color-stops...) {
$_angle-with-vendor-prefix: "";
$_angle: "";
@if $angle == "to top" or $angle == "bottom" {
$_angle-with-vendor-prefix: bottom;
$_angle: to top;
} @else if $angle == "to right" or $angle == "left" {
$_angle-with-vendor-prefix: left;
$_angle: to right;
} @else if $angle == "to bottom" or $angle == "top" {
@npinto
npinto / cv2_detect.py
Created September 5, 2012 07:13
Simple face detection with OpenCV 'cv2' python bindings from 2.4.x
import cv2
import cv2.cv as cv
def detect(img, cascade_fn='haarcascades/haarcascade_frontalface_alt.xml',
scaleFactor=1.3, minNeighbors=4, minSize=(20, 20),
flags=cv.CV_HAAR_SCALE_IMAGE):
cascade = cv2.CascadeClassifier(cascade_fn)
rects = cascade.detectMultiScale(img, scaleFactor=scaleFactor,
@lastland
lastland / BeyesianAvg.py
Created August 11, 2012 07:14
尝试用这篇post: http://www.matrix67.com/blog/archives/5044 中的方法实现的一个自动中文抽词算法的Python程序
# -*- coding=utf-8 -*-
import collections
# Usage:
# 我的做法是把WordsDetector.py里的结果输出到文件,
# 然后把文件名放到下面的names列表中,运行本程序。
names = ['name0',
'name1',
'name2',
@jrstarke
jrstarke / index.html
Created July 22, 2012 20:42
Clustering of Bus Stops. For Breeze (https://github.com/lgrammel/breeze)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Bus stops on UVic Bus Lines, Victoria, BC</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/d3/2.8.1/d3.v2.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/simplegeo/polymaps/v2.5.0/polymaps.min.js"></script>
<script type="text/javascript" src="jquery.qtip.min.js" ></script>
<link rel="stylesheet" type="text/css" href="jquery.qtip.min.css">
var FFT = (function() {
"use strict";
var FFT = function() {
initialize.apply(this, arguments);
}, $this = FFT.prototype;
var FFT_PARAMS = {
get: function(n) {
return FFT_PARAMS[n] || (function() {
@paolorossi
paolorossi / html5-video-streamer.js
Created March 7, 2012 13:21
Node.js HTML5 video streamer
/*
* Inspired by: http://stackoverflow.com/questions/4360060/video-streaming-with-html-5-via-node-js
*/
var http = require('http'),
fs = require('fs'),
util = require('util');
http.createServer(function (req, res) {
var path = 'video.mp4';
@stober
stober / tiles.py
Created February 10, 2012 20:46
Tile Coding in Python
#!/usr/bin/python
"""
Author: Jeremy M. Stober
Program: TILES.PY
Date: Monday, March 31 2008
Description: A simple CMAC implementation.
"""
import os, sys, getopt, pdb
from numpy import *