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
#include "ruby.h"
#include "Python.h"
// #include "sre.h"
#include "re.h"
#include "st.h"
#include "rubyio.h"
// #include "structmember.h" -- Clashes with Ruby
#include <string.h>
/*
@leepa
leepa / http.js
Created July 17, 2010 08:27
This is a slight mod on the original - it supports HTTPS and actually has error handling!
// Express - HTTP - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
/**
* Module dependencies.
*/
var http = require('http'),
parse = require('url').parse,
queryString = require('querystring')
// A Simple Javascript syntax highlighted Editor within 1023 bytes (< 1Kb)
// Demo: http://failboat.me/jpad.html
(d=document).write('<style>#p,#d{text-shadow:0 0 20px #39E;top:0;left:0;white-space:pre;color:#756;width:100%;height:100%;padding:10px;border:none;line-height:20px;position:absolute;background:transparent;font:14px "Courier New"}#p{opacity:0.4}</style><div id="d">JS</div><textarea id="p"></textarea>');p=d[g="getElementById"]("p");n="length";function j(b,a){l=[];for(_ in a){i=0;$=a[_];for(m=b.match(a[_]);$.test(b);)l.push([$.lastIndex-m[i][n],m[i++][n],_])}l.sort(function(c,f){return c[0]+1/c[1]-f[0]-1/f[1]});h=0;z=[];for(_ in l){$=l[_];e=$[0]+$[1];if(!(e<=h)){z.push([h,$[0]-h,g],$);h=e}}z.push([h,b[n],g]);return z}p.onkeyup=function(){var b=d[g]("d"),a=p.value;t=j(a,{"#288;border-bottom:dashed 1px #ccc":/\/\/.*|\/\*(.|\n)+\*\//g,"#D24":/"[^"\n]*"|'[^'\n]*'/g,"#08c":/\b(else|switch|break|throw|case|catch|new|finally|null|try|const|for|continue|function|var|if|return|delete|while|do|with|in)(?!\w)/g}
@copenhas
copenhas / gist:664062
Created November 5, 2010 12:27
C Macro that effectively does hierarchical type casting. Credit goes out to an unknown Linux kernel developer.
/*
* Name: container_of
* Parameters: ptr - Pointer to the inner structure that you have.
* Parameters: type - The type of outer structure you want to have.
* Parameters: member - The member in the outer structure for the inner.
* Returns: type * - Pointer to the outer structure you wanted.
* Description:
* This is a macro used to get to a child structure when you have a pointer
* to the root structure. Notice that this makes no checks or validation.
* Use when you know what you have and what you want.
@leegao
leegao / flux.c
Created November 14, 2010 00:42
Calculates the flux over a Cat
// Calculates the flux of f(x,y) = x^2/2 + y^2/2 over a cat. CAN I HAZ SUM FLUXZ?
#include "flux.h"
double M(double x, double y){
return x; // X component of our gradient field.
}
double N(double x, double y){
return y; // Y component of our gradient field.
}
@nowl
nowl / perlin.c
Created February 15, 2011 19:04
Perlin Noise in C
#include <stdio.h>
static int SEED = 0;
static int hash[] = {208,34,231,213,32,248,233,56,161,78,24,140,71,48,140,254,245,255,247,247,40,
185,248,251,245,28,124,204,204,76,36,1,107,28,234,163,202,224,245,128,167,204,
9,92,217,54,239,174,173,102,193,189,190,121,100,108,167,44,43,77,180,204,8,81,
70,223,11,38,24,254,210,210,177,32,81,195,243,125,8,169,112,32,97,53,195,13,
203,9,47,104,125,117,114,124,165,203,181,235,193,206,70,180,174,0,167,181,41,
164,30,116,127,198,245,146,87,224,149,206,57,4,192,210,65,210,129,240,178,105,
@jdp
jdp / compiler.py
Created February 21, 2011 10:31
A simple compiler targeting 6502 family chips
class Scanner():
def __init__(self, source):
self.source = source
self.position = 0
self.buffer = ''
self.line = 1
def current(self):
return self.source[self.position]
@bavardage
bavardage / gist:939140
Created April 24, 2011 00:22
POC Linux Keylogger
#!/usr/bin/env python
import re, collections
from subprocess import *
def sanitize_keybinding(binding):
d = {'space': ' ',
'apostrophe': "'",
'BackSpace': ' (<-)',
'Return': '↵ \n',
@msantos
msantos / bpf.c
Last active April 2, 2024 18:54
Example of using bpf to capture packets
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <err.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#!/bin/bash
NYAN=('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmbbbbbbbbbbbbbbbbbbbbbbbbbbb'
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmbmbbbbbbbbbbbbbbbbbbbbbbbbbb'
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmbbbbbbbbbbbbbbbbbbbbbbbbbbb'
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmb'
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmb'