Skip to content

Instantly share code, notes, and snippets.

View leegao's full-sized avatar

Lee Gao leegao

  • Google
  • Jersey City, NJ
View GitHub Profile
@leegao
leegao / IP.tex
Created April 17, 2013 17:45
Integer programming
\documentclass[12pt,a4paper,svgnames]{article}
\usepackage{amsmath}
\usepackage{fullpage}
\usepackage{amsfonts}
\usepackage{amssymb,amsthm}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{algorithm}
@leegao
leegao / EllipseZero.m
Last active December 16, 2015 07:49
Finding the quadrants on which an ellipse resides upon
function [ x1,x2,y1,y2 ] = FindQuad( a,b,h,k,phi )
%FINDQUAD Summary of this function goes here
% Detailed explanation goes here
x = @(t) h + cos(phi)*a*cos(t) - sin(phi)*b*sin(t);
y = @(t) k + sin(phi)*a*cos(t) + cos(phi)*b*sin(t);
t = 0:0.05:2*pi;
subplot(3,1,1);
plot(x(t),y(t))
axis equal
def gi(n,i):
return n&(1<<i)
def b(n):
l = []
for k in filter(lambda n: n%5 < 4, range(19)):
if gi(n,k) and not gi(n,k+1) and not gi(n,k+5):
l.append(k)
return l
@leegao
leegao / ast.ml
Last active December 15, 2015 15:59
Continuation translation of Imp with break into uML (which is a subset of ocaml), now with a parser
type var = string;;
type ar = Int of int | Var of var | Add of ar * ar;;
type bl = True | False | And of bl * bl | Or of bl * bl | Eq of ar * ar | Le of ar * ar;;
type com = Skip | Assgn of var * ar | Seq of com * com | If of bl * com * com | While of bl * com | Break;;
(* representation for stores *)
module Store = Map.Make(struct
type t = var
let compare = Pervasives.compare
end)
@leegao
leegao / check.ml
Created November 25, 2012 00:45
Simple Constraint/Unification Type Inference engine for STLC
open Ast
exception TypeError
exception UnificationError
(* ---------- EQUALITY ---------- *)
(* [typ_eq t1 t2] returns [true] iff [t1] and [t2] are equal *)
let rec typ_eq (t1:typ) (t2:typ) : bool =
match t1,t2 with
def pthing(title,ext,n):
overlay = '''
<GroundOverlay>
<name>res</name>
<TimeSpan>
<begin>%s</begin>
<end>%s</end>
</TimeSpan>
<Icon>
@leegao
leegao / swinger.m
Created October 25, 2012 01:37
Swinger
function swinger(x0,y0,m1,m2,l1,l2)
% SWINGER Classic double pendulum.
% SWINGER(x,y) starts the pendulum at the given initial position.
% The initial position can reset with the mouse.
%
% SWINGER with no arguments starts at (x,y) = (0.862,-0.994).
% What is interesting about the resulting orbit?
%
% SWINGER(0,2) starts in an unstable vertical position.
% How long does it stay there and what causes it to move?
@leegao
leegao / hotpatch.c
Created October 22, 2012 22:10
Context-aware Hot Patching
#include <windows.h>
#include <stdio.h>
//68 BE BA FE CA
const unsigned char OP_PUSH = 0x68;
const unsigned char OP_JMP = 0xE9;
static DWORD rets[10000];
static PDWORD r = NULL;
struct patchwork{
@leegao
leegao / vcgen.ml
Created September 28, 2012 16:14
Verification Conditions generator for a simple imperative language using Z3 proover
open Ast
(* lexp_of_aexp: convert an aexp into an lexp *)
let rec lexp_of_aexp (a:aexp) : lexp =
match a with
| Int n ->
LInt n
| Var x ->
LPVar x
| Plus(a1,a2) ->
@leegao
leegao / scrolling.html
Created September 15, 2012 23:59
FANCY AS FUCK
<html>
<head>
<title>Scrolling Cards</title>
<script src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("bottom", "1px");// Math.max(0, (($(window).height() - this.outerHeight()) / 2) +
// $(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - this.outerWidth()) / 2) +