Skip to content

Instantly share code, notes, and snippets.

View nlf's full-sized avatar

nlf nlf

  • Code4rena
  • Kennewick, WA
View GitHub Profile
var express = require('express'),
cgh = require('connect-githubhook');
var app = express.createServer();
var hook = cgh.createHook({ 'secretpath': 'https://github.com/test/test' }, function (payload) {
//do whatever
});
app.use(hook);
@nlf
nlf / update-itunes.rb.js
Created August 9, 2012 16:14
update your itunes liberry
require 'osx/cocoa'
require 'optparse'
include OSX
OSX.require_framework 'ScriptingBridge'
iTunes = SBApplication.applicationWithBundleIdentifier_('com.apple.iTunes')
$opts = {}
optparse = OptionParser.new do |args|
args.banner = 'Usage: update-itunes.rb [opts] <path>'
@nlf
nlf / clw.cpp
Created August 22, 2012 22:18
znc capslock wednesday module
/* CLW module for ZNC
* Build with znc-buildmod and load with /msg *status loadmod clw
* Module triggers Wednesdays from 2PM to 4PM Pacific time, but uses UTC
* and converts to make sure it works in any time zone. Will ONLY caps
* messages sent to #thezone
*
* Changes:
* 1/4/2012
* added handling of irc connected event so module is properly re-enabled
* 4/30/2011
@nlf
nlf / unique.js
Created August 23, 2012 22:19
check if array contents are unique
function _isUnique(array) {
function _sort(item) {
if (!item || typeof item !== 'object' || Array.isArray(item)) {
return item;
}
var result = [];
Object.keys(item).sort().forEach(function (key) {
result.push({ key: key, value: _sort(item[key]) });
});
return result;
@nlf
nlf / gist:3555689
Created August 31, 2012 16:45
tzbot feature requests
Comment here what features/commands you want added to the bot.
This is what I already have planned:
* Weather, since Syber's bot sucks at it
var http = require('http'),
fs = require('fs');
var data = fs.readFileSync('./sample_request.txt');
var parser = http.parsers.alloc();
parser.reinitialize(1);
console.log(parser);
parser.onIncoming = function (res) {
console.log('onIncoming:', res);
@nlf
nlf / varint.js
Created October 21, 2012 02:38
varints
function lshift(num, bits) {
return num * Math.pow(2, bits);
}
function rshift(num, bits) {
return num / Math.pow(2, bits);
}
function encode(num) {
if (num === 0) return new Buffer([0x00]);
@nlf
nlf / gist:3991059
Created November 1, 2012 01:32
read string from buffer
function reads(buf, start, end) {
var pos = start,
bytes = [],
byte,
byte2;
while (pos < end) {
byte = buf[pos];
if (byte > 191 && byte < 224) {
pos++;
byte = ((byte & 31) << 6) | (buf[pos] & 63);
@nlf
nlf / gist:3995302
Created November 1, 2012 17:43
butils benchmark
100,000,000 iterations of each function. lines starting with Buffer# are the core implementations, those with butils# are mine.
Buffer#writeInt8: 15230ms
butils#writeInt: 165ms
Buffer#readInt8: 3074ms
butils#readInt: 162ms
@nlf
nlf / gist:4035312
Created November 7, 2012 23:21
riak madness
var client = require('simpleriak').createClient({ bucket: 'hb' });
function map(v, keydata, arg) {
if (v.values[0].metadata['X-Riak-Deleted']) return [];
var links = v.values[0].metadata.Links,
ret = [];
ret.push([v.bucket, v.key]);
for (var i = 0; i < links.length; i++) {
if (links[i][2] === arg) {
ret.push([links[i][0], links[i][1]]);