Skip to content

Instantly share code, notes, and snippets.

View clarle's full-sized avatar

Clarence Leung clarle

  • Netflix
  • Los Gatos, CA
  • 04:16 (UTC -07:00)
  • X @clarler
View GitHub Profile
@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 / gene_reader.py
Created June 15, 2012 01:28
Gets unspliced gene data from Wormbase REST API, given a CSV file.
import csv
import requests
import bs4 as bs
def wormbase_url(gene_id):
"""
Return the correct REST API URL, given the gene ID.
"""
url = "http://www.wormbase.org/rest/widget/cds/" + gene_id + "/sequences"
return url
@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)
@clarle
clarle / app.js
Created July 26, 2012 07:35
Short tutorial on how to use Express and node-mysql
// Module dependencies
var express = require('express'),
mysql = require('mysql');
// Application initialization
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
@clarle
clarle / Procfile
Created July 31, 2012 06:52
Simultaneous Mojito deployment technique for Heroku and Nodejitsu
web: node server.js