Skip to content

Instantly share code, notes, and snippets.

View clarle's full-sized avatar

Clarence Leung clarle

  • Netflix
  • Los Gatos, CA
  • 14:49 (UTC -07:00)
  • X @clarler
View GitHub Profile
@clarle
clarle / manage.py
Created April 7, 2014 22:40
Client/Server management script for COMP 512
import os
from time import sleep
from optparse import OptionParser
# Remember to add the trailing slash!
SERVER_FOLDER = "/home/2010/cleung24/comp512/a3/servercode/"
CLIENT_FOLDER = "/home/2010/cleung24/comp512/a3/clientsrc/"
MIDDLEWARE_PORT = 5678
@clarle
clarle / array_promises_in_sequence.js
Last active August 29, 2015 14:08
Promise-based operations in sequence, with Bluebird
var Promise = require('bluebird'),
data = ['a', 'b', 'c', 'd', null, 'e'];
/**
* A long running task to run for each element of the array.
* It must return a promise
*/
function doThing(arg) {
return new Promise(
function (resolve, reject) {
@clarle
clarle / generate.py
Created August 8, 2015 04:54
Blood sugar random data generation
import random
import csv
DAYS = 7
HOURS = 24
data = []
for day in range(DAYS):
for hour in range(HOURS):
@clarle
clarle / node-post.js
Created September 4, 2011 22:15
Node POST request
// We need this to build our post string
var querystring = require('querystring');
var http = require('http');
var fs = require('fs');
function PostCode(codestring) {
// Build the post string from an object
var post_data = querystring.stringify({
'compilation_level' : 'ADVANCED_OPTIMIZATIONS',
'output_format': 'json',
@clarle
clarle / montecarlo.py
Created February 29, 2012 00:40
Monte Carlo for COMP 424
from random import random, shuffle
def monte_carlo(draws, reds, blues):
cases = []
for i in xrange(draws):
red_draws = [1] * reds
blue_draws = [0] * blues
total = red_draws + blue_draws
shuffle(total)
utility = total.pop() + total.pop() # pop two off
@clarle
clarle / circuit_solver.py
Created March 21, 2012 02:59
Simple Circuit Solver
oparray = [ \
lambda x, y: False, # FALSE
lambda x, y: x and y, # AND
lambda x, y: x and (not y), # X AND NOT Y
lambda x, y: x, # X
lambda x, y: (not x) and y, # NOT X AND Y
lambda x, y: y, # Y,
lambda x, y: x != y, # XOR
lambda x, y: x or y, # OR
lambda x, y: not (x or y), # NOR
@clarle
clarle / backprop.py
Created March 21, 2012 16:37
Backpropagation Algorithm
from math import exp
class Edge:
def __init__(self, edgetup, weight):
self.vertex_out = edgetup[0]
self.vertex_in = edgetup[1]
self.weight = weight
class Unit:
def __init__(self, number, input_edges, output_edges):
@clarle
clarle / convolution.m
Created March 22, 2012 23:48
Convolution Script for BIOL 319
clear all; close all;
A = imread('BrownDischer079.tiff');
A = single(A);
scale = max(max(A))/256;
A = A/scale;
figure(1);
co=[0:255]/256; colormap([co;co;co]');
image(A); axis off tight; title('original image');
[x,y] = meshgrid(-25:25);
@clarle
clarle / genet.py
Created July 13, 2012 03:34
genet - Python screen scraper for the Cystic Fibrosis Mutation Database
"""
genet - Python screen scraper for the Cystic Fibrosis Mutation Database
Installation
-------------
$ pip install requests pyquery
$ python
> import genet
@clarle
clarle / genet_test.py
Created July 19, 2012 02:43
Genet Test Program
import genet
aa_values = genet.extract_aa_values("Cyto loop1 (56 aa) 139/140-194/195")
raw_html = genet.search_by_consequence(aa_values)
print genet.parse_result_data(raw_html)