Skip to content

Instantly share code, notes, and snippets.

@bhelx
bhelx / libtre_test.c
Created December 19, 2011 19:57
test of libtre fuzzy regex matcher
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 January 21, 2012 21:51
reduce bitwise OR flags
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
@bhelx
bhelx / pry_trick.rb
Created January 26, 2012 06:37
Pry trick
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 March 23, 2012 19:16
Ruby-esque object construction in javascript
// 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 July 23, 2012 02:27
Priority Queue with re assignable priorities
class PQueue
def initialize
@q = {}
end
def push(object, priority)
values = @q[priority] ||= []
values.push object
sync
@bhelx
bhelx / dump.js
Created September 24, 2012 22:57
body dump middleware
app.all('*', function (req, res, next) {
req.setEncoding('utf-8');
req.on('data', function (data) {
console.log(data);
});
// next();
});
@bhelx
bhelx / vim.rb
Created October 27, 2012 07:21
vim update
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 November 8, 2012 20:34
hacked Backbone model
/** 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 November 25, 2012 20:21
Non _id document reference
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' },
/**
* 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