Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Eckel bhelx

View GitHub Profile
@bhelx
bhelx / index.html
Created Dec 15, 2011
"tail -f" a file node 0.6.5 pipe to socket.io,
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Websockets tail Server</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<style type="text/css" rel="stylesheet">
body{background-color:#222;}
#info{ font-size: 32px; color:#000;text-shadow:#444 1px 1px 2px; text-align:right;margin:20px 10px;text-transform:lowercase;}
@bhelx
bhelx / libtre_test.c
Created Dec 19, 2011
test of libtre fuzzy regex matcher
View libtre_test.c
Compiled Regex
Created Default params
cost_ins -> 1
cost_del -> 1
cost_subst -> 1
max_cost -> 2147483647
max_ins -> 2147483647
max_del -> 2147483647
max_subst -> 2147483647
max_err -> 2147483647
@bhelx
bhelx / reduce_flags.rb
Created Jan 21, 2012
reduce bitwise OR flags
View reduce_flags.rb
REG_EXTENDED = 1
REG_ICASE = (REG_EXTENDED << 1)
REG_NOSUB = (REG_ICASE << 1)
REG_NEWLINE = (REG_NOSUB << 1)
flags = [REG_EXTENDED, REG_NOSUB]
p flags.reduce :|
# => 5
View pry_trick.rb
require 'pry'
class Object
LABELS = [:label1, :label2]
def breakpt(label, target=self)
LABELS.include?(label) ? Pry.start(target) : nil
end
@bhelx
bhelx / rb.js
Created Mar 23, 2012
Ruby-esque object construction in javascript
View rb.js
// kind of like ruby openstruct
var OpenObject = function () {
this.construct = function (defaults, params) {
for (var attr in defaults) this[attr] = defaults[attr];
for (var attr in params) this[attr] = params[attr];
};
}
var Circle = function (opts) {
@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' },
You can’t perform that action at this time.