Skip to content

Instantly share code, notes, and snippets.

View vweevers's full-sized avatar

Vincent Weevers vweevers

View GitHub Profile
@vweevers
vweevers / benchmark-random.js
Created June 25, 2019 14:57
Benchmark of buffer comparison
'use strict'
const Benchmark = require('benchmark')
const prb = require('pseudo-random-buffer')
const randomBytes = prb('a seed')
const suite = new Benchmark.Suite()
console.log('node', process.version)
const a = randomBytes(256)
@vweevers
vweevers / disk-alert.cron
Created July 19, 2018 06:32
Send AWS EC2 disk usage alerts to Marbot
#!/bin/sh
#
# Adapted from https://gist.github.com/djangofan/3113588
# Save to e.g. /etc/cron.daily/disk-alert.cron
THRESHOLD=50
ENDPOINT_ID=REPLACE_ME
REGION=REPLACE_ME
AWS_INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
EC2_NAME=$(aws ec2 describe-tags --region $REGION --filters "Name=resource-id,Values=$AWS_INSTANCE_ID" "Name=key,Values=Name" --output text | cut -f5)
@vweevers
vweevers / example.js
Created June 14, 2016 06:59
Callback generators
const fs = require('fs')
// echoes "this is a test"
run(test, function done (err) {
console.log('done', err)
})
function* test() {
console.log(yield echo('this'))
@vweevers
vweevers / output.log
Created March 12, 2016 12:14
Reading Firefox metadata
> firefox -app path/to/application.ini -attach-console | more
{
"name": "firefox",
"version": "46.0a2",
"source_revision_url": "https://hg.mozilla.org/releases/mozilla-aurora/rev/10e1774de80ea0c93e26fb98d093a4965cfa1e2",
"update_channel": "aurora",
"release_channel": "developer"
}
@vweevers
vweevers / simplify_iterator.cc
Created February 18, 2016 14:45
LevelDOWN key comparison refactor for reverse mode
// The original code (iterator.cc#L95):
if (lt != NULL) {
if (lt->compare(key_) <= 0)
dbIterator->Prev();
} else if (lte != NULL) {
if (lte->compare(key_) < 0)
dbIterator->Prev();
} else if (start != NULL) {
if (start->compare(key_))
dbIterator->Prev();
@vweevers
vweevers / post-hooks.js
Created February 7, 2016 02:46
bytespace/level-sublevel post hooks
const wrap = require('bytespace') // Or require('level-sublevel')
const disk = require('test-level')({ mem: true, wrap })
, assert = require('assert')
const db = disk()
, sub1 = db.sublevel('sub1')
, sub2 = db.sublevel('sub2')
let called = []
@vweevers
vweevers / skip-scan.js
Last active January 29, 2016 11:26
Bytespace skip scan benchmark
require('require-rebuild')();
const bytespace = require('bytespace')
, bytewise = require('bytewise-core')
, sorted = require('sorted')
, disk = require('test-level')({ mem: false, clean: true })
, noop = function(){}
, profiler = require('v8-profiler')
, fs = require('fs')
@vweevers
vweevers / batch-bench.js
Created January 24, 2016 20:53
Memdown put/batch with iterator benchmark
const MemDOWN = require('./')
const alternatives = {
'remove and insert': function(db, array) {
var i = -1
, len = array.length
, tree = db._store[db._location]
, key, value
while (++i < len) {
@vweevers
vweevers / keybase.md
Created August 19, 2015 07:44
keybase.md

Keybase proof

I hereby claim:

  • I am vweevers on github.
  • I am vweevers (https://keybase.io/vweevers) on keybase.
  • I have a public key whose fingerprint is CFA6 A9F0 022B F778 AC82 6963 C7D0 0308 829F 227B

To claim this, I am signing this object:

@vweevers
vweevers / Example output
Last active August 29, 2015 14:01
Test script to fix Windows browser detection (https://github.com/substack/browser-launcher/issues/7)
chrome 35.0.1916.114 [common location]
@ C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
ff 23.0.1.4974 [common location]
@ C:\Program Files (x86)\Mozilla Firefox\firefox.exe
ie 11.0.9600.17041 [common location]
@ C:\Program Files\Internet Explorer\iexplore.exe
ie 11.0.9600.17041 [registry]