Skip to content

Instantly share code, notes, and snippets.

View DTrejo's full-sized avatar

David Trejo DTrejo

View GitHub Profile
var sys = require('sys')
, url = require('url')
, http = require('http')
, eyes = require('eyes')
, querystring = require('querystring')
, io = require(__dirname + '/lib/socket.io-node')
, PORT = 80 // MAKE SURE THIS IS SAME AS SOCKET.IO
, static = require('node-static')
public class Bitops {
// Takes a character and returns the number of ones
// contained in its binary representation
static int numOnes(char c) {
int hex = (int) c;
int sum = 0;
// we want unsigned comparison
// this works fine if java uses 2s complement (it does I think).
while (hex > 0) {
@DTrejo
DTrejo / doctype.js
Created November 6, 2010 07:59
making sure that node-htmlparser doesn't throw errors when reading html with a doctype
var rawHtml = '<!DOCTYPE HTML><html lang="en"><head><title>LEtss goo</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="Content-Language" content="en-us"><link rel="icon" type="image/png" href="/favicon.png"><link rel="stylesheet" type="text/css" href="css/style.css"><link rel="stylesheet" type="text/css" href="css/jquery.gritter.css"><link rel="stylesheet" type="text/css" href="css/jScrollPane.css"><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script type="text/javascript" src="js/lib/jquery.mousewheel.js"></script><script type="text/javascript" src="js/lib/jquery.em.js"></script><script type="text/javascript" src="js/lib/jScrollPane.js"></script><script type="text/javascript" src="js/lib/jquery.autolink.js"></script><script type="text/javascript" src="js/lib/jquery-css-transform.js"></script><script type="text/javascript" src="js/lib/jquery-animate-css-rotate-scale.js"></script><script type="text/javasc
@DTrejo
DTrejo / ERR.html
Created November 9, 2010 20:33
hist.rvals is undefined the first time you run it. The second time you run it, when you click the link, it works just fine :|
<html>
<head>
<title>ERR</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="pixastic/pixastic.core.js"></script>
<script type="text/javascript" src="pixastic/actions/colorhistogram.js"></script>
<style type="text/css" media="screen">
#testImage {width:auto;height:auto;}
</style>
</head>
@DTrejo
DTrejo / run.py
Created November 15, 2010 02:17
reruns the given file whenever it changes. usage: python3 run.py myfile.py
#!/course/cs053/bin/python3
import os, time
import sys
"""
reruns the given file whenever it changes.
usage: python3 run.py myfile.py
"""
def stat(f):
@DTrejo
DTrejo / run.py
Created November 15, 2010 02:19
reruns the given file whenever it changes. usage: python3 run.py myfile.py
#!/course/cs053/bin/python3
import os, time
import sys
"""
reruns the given file whenever it changes.
usage: python3 run.py myfile.py
"""
def stat(f):
@DTrejo
DTrejo / server.js
Created December 5, 2010 06:57
dtrejo.com w/ proxying to compare
var util = require('sys') // update this at some point
, ns = require('node-static')
, http = require('http')
, fileServer = new ns.Server('./public');
http.createServer(function (request, response) {
request.addListener('end', function () {
fileServer.serve(request, response, function (err, result) {
if (err) { // An error as occurred
function findBeer(words) {
//...code...
getResults(word, function(err, result){
// now you can access things!
console.log(err, result);
});
}
function getResults(word, callback) {
@DTrejo
DTrejo / ws
Created March 20, 2011 17:59
ws test
var fs = require('fs')
, path = './DELETEME.txt'
, stream = fs.createWriteStream(path, { flags: 'w+', encoding: 'utf8' })
, data = { "I":0.18181818181818182,"bought":0.18181818181818182 }
;
function cb(err) {
if (err) console.log(err);
console.log('cool, all done.');
}
@DTrejo
DTrejo / crazyiness.js
Created March 21, 2011 01:40
underscore: keys, values, zip, max => undefined
var _ = require('underscore')._;
var data = {"1":0.000007223714765952328,"2":0.0000039749105916010536,"3":0.0000032965765671970454,"7":0.0000020878318258914622,"8":0.000002736989620496371,"9":0.000003076694134649906,"10":0.0000013715180458375907,"12":0.000001159906569939701,"15":6.457211832654003e-7,"18":6.457211832654003e-7,"19":0.0000026097897823643283,"20":0.0000026097897823643266,"21":9.490144663143008e-7,"23":3.4414810316892216e-7,"24":8.821824616442793e-7,"26":0.0000024947065913923583,"38":0.000004404915773841593,"40":0.0000023785425864586267,"41":0.0000018918312871343038,"42":0.0000014913084470653296,"44":0.0000023665042941778225,"51":9.942056313768864e-7,"57":0.0000010616094029956584,"58":0.0000024056413215874137,"100":4.971028156884432e-7,"230":0.0000015658738694185964,"1998":0.000026218026718821232,"the":0.0007400023061007896,"Honourable":0.00022929140436720472,"Gildas":0.00001957342336773246,"L":0.00001957342336773246,".":0.0006657129490331946,"Molgat":0.00001957342336773246,",":0.0003656978308864