Skip to content

Instantly share code, notes, and snippets.

@bhelx
bhelx / pq.rb
Created Jul 23, 2012
Priority Queue with re assignable priorities
View pq.rb
class PQueue
def initialize
@q = {}
end
def push(object, priority)
values = @q[priority] ||= []
values.push object
sync
@bhelx
bhelx / dump.js
Created Sep 24, 2012
body dump middleware
View dump.js
app.all('*', function (req, res, next) {
req.setEncoding('utf-8');
req.on('data', function (data) {
console.log(data);
});
// next();
});
@bhelx
bhelx / vim.rb
Created Oct 27, 2012
vim update
View vim.rb
require 'formula'
class Vim < Formula
# Get stable versions from hg repo instead of downloading an increasing
# number of separate patches.
url 'https://vim.googlecode.com/hg/', :revision => '57e8b75298d6'
version '7.3.712'
homepage 'http://www.vim.org/'
head 'https://vim.googlecode.com/hg/'
@bhelx
bhelx / hacked_bone.js
Created Nov 8, 2012
hacked Backbone model
View hacked_bone.js
/** WTF MAYNE **/
Admin.User = Backbone.Model.extend({
idAttribute: '_id',
setAction: function (action) {
this.action = action;
},
getAction: function () {
if (!this.action) return '';
var action = this.action;
this.action = null;
@bhelx
bhelx / test.js
Created Nov 25, 2012
Non _id document reference
View test.js
var mongoose = require('mongoose');
var db = mongoose.createConnection('localhost', 'test');
var UserSchema = mongoose.Schema({
name: String,
phone: Number
});
var MemorySchema = mongoose.Schema({
user: { type: Number, ref: 'User' },
View recommendations.js
/**
* A little code from Collective Intelligence translated to javascript
*/
var critics = {
"Lisa Rose": {
"Lady in the Water" : 2.5
, "Snakes on a Plane" : 3.5
, "Just My Luck" : 3.0
, "Superman Returns" : 3.5
@bhelx
bhelx / face_extractor.py
Last active Dec 10, 2015
Recursively walk given directory, find faces in jpegs, extract the sub images into their own images for training set
View face_extractor.py
#!/usr/bin/python
import cv
import time
import Image
import fnmatch
import os
import sys
def DetectFace(image, faceCascade):
@bhelx
bhelx / trace.js
Last active Dec 11, 2015
This is an incomplete thought. Doesn't actually show enough information to do anything useful.
View trace.js
/**
* Intelligent Traceroute
*
* Do a traceroute on a domain, prints a json array
* of the hops with their physical locations.
*
* //Example
* node trace.js google.com
*
* npm install traceroute async underscore request
View colored_nicks.js
var NickList = function () {
this.nicks = [];
this.colorMap = {};
this.colors = [
'#ff00ff',
'#00007f',
'#009300',
'#ff0000',
'#7f0000',
'#9c009c',