Skip to content

Instantly share code, notes, and snippets.

View kkaefer's full-sized avatar
🏳️‍🌈

Konstantin Käfer kkaefer

🏳️‍🌈
View GitHub Profile
var fs = require('fs');
var Buffer = require('buffer').Buffer;
Buffer.prototype.randomize = function() {
var fd = fs.openSync('/dev/random', 'r');
fs.readSync(fd, this, 0, this.length, 0);
fs.closeSync(fd);
return this;
}
@kkaefer
kkaefer / bump
Created May 11, 2011 15:44
Bumps version numbers in package.json and creates a git tag for it
#!/usr/bin/env sh
version() {
ruby <<"EOS"
doc = File.read './package.json'
regex = /("version"\s*:\s*")([^"]+)(")/
cur = regex.match(doc)
if ENV['CMD'] == 'major' then
nxt = (cur[2].to_i + 1).to_s + ".0.0"
elsif ENV['CMD'] == 'minor' then
function alphaImageLuminosity(el) {
if (!HTMLCanvasElement || !el.complete) return -1;
var canvas = document.createElement('canvas');
canvas.setAttribute('width', el.width);
canvas.setAttribute('height', el.height);
var c = canvas.getContext('2d');
c.drawImage(el, 0, 0);
var r = 0, g = 0, b = 0, total = 0;
@kkaefer
kkaefer / pull-request
Created September 22, 2011 10:09
Converts an issue into a pull request. Works within one repository only and always pulls a branch into master. Requires github.user and github.token to be set.
#!/bin/sh
BRANCH_NAME=$(git symbolic-ref -q HEAD)
BRANCH_NAME=${BRANCH_NAME##refs/heads/}
BRANCH_NAME=${BRANCH_NAME:-HEAD}
REPO_NAME=`git config --get-regexp remote\..+\.url | perl -p -e 's/^remote\.\w+\.url\s+git\@github.com:(.+).git/\$1/'`
echo "Pulling $BRANCH_NAME into master of $REPO_NAME"
read -p "Issue #: " GITHUB_ISSUE
// ==UserScript==
// @name GitHub monospace
// @namespace http://kkaefer.com
// @match https://github.com/*
// @author Konstantin Käfer
// @description Changes GitHub's table listing to monospace
// ==/UserScript==
(function() {
var style = document.createElement('style');
server {
listen 443;
server_name localhost;
access_log /var/log/nginx/tilestream-ui.access.log;
ssl on;
ssl_certificate /Users/kkaefer/Code/modules/tilestream-pro/certificates/server.cer;
ssl_certificate_key /Users/kkaefer/Code/modules/tilestream-pro/certificates/server.key;
location / {
@kkaefer
kkaefer / longjmp.cpp
Created February 7, 2012 16:01
child processes don't terminate after longjmp
#include <node.h>
// C standard library
#include <cstdlib>
#include <ctime>
#include <setjmp.h>
using namespace v8;
@kkaefer
kkaefer / README.md
Created February 29, 2012 21:05
Missing Tiles

Usage:

node missingtiles.js database.bigtiles > missing.txt node filter_blank.js database.bigtiles missing.txt > missing_filtered.txt node generate_coords.js missing_filtered.txt > missing.json

Note: the first task takes pretty long, like a couple of hours.

missingtiles.js and filter_blank.js output tms coordinates

Mon Jan 28 22:40:33 2013
panic(cpu 0 caller 0xffffff80224b1b19): "Spinlock acquisition timed out: lock=0xffffff804af48030, lock owner thread=0xdeadbeefdeadbeef, current_thread: 0xffffff8039438550, lock owner active on CPU 0xffffffff, current owner: 0xdeadbeefdeadbeef"@/SourceCache/xnu/xnu-2050.20.9/osfmk/i386/locks_i386.c:363
Backtrace (CPU 0), Frame : Return Address
0xffffff8030843c00 : 0xffffff802241d626
0xffffff8030843c70 : 0xffffff80224b1b19
0xffffff8030843cc0 : 0xffffff80224ad06d
0xffffff8030843ce0 : 0xffffff7fa3c11e22
0xffffff8030843d10 : 0xffffff7fa3c3689b
0xffffff8030843d30 : 0xffffff7fa3bb4137
0xffffff8030843d70 : 0xffffff8022832dbb
@kkaefer
kkaefer / shared_ptr.hpp
Created April 19, 2013 14:23
Use std::shared_ptr without tr1 on glibc++ and libc++
#if defined(_LIBCPP_VERSION)
#include <memory>
#else
#include <tr1/memory>
namespace std { template <typename T> using shared_ptr = tr1::shared_ptr<T>; }
#endif