Skip to content

Instantly share code, notes, and snippets.

View robey's full-sized avatar

Robey Pointer robey

View GitHub Profile
@robey
robey / arrow.js
Created July 3, 2015 21:51
the `=>` still doesn't preserve `this` in ES6
const callback = (n) => {
console.log(this.sum + n);
};
class Adder {
constructor(sum) {
this.sum = sum;
}
work(callback) {
@robey
robey / curses_skull.js
Last active August 29, 2015 14:24 — forked from rhwlo/curses_skull.py
obligatory node port!
#!/usr/bin/env node
const SKULLS = [`
▒▒▒▒▒▒▒
▒▒▓▓▓▓▓▓▓▓▓▓▓▒▒
▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒
▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒
▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒
▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒
▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒
@robey
robey / test2.js
Created June 27, 2015 01:17
test case for memory leak while recursing a while-loop in bluebird
var Promise = require('bluebird');
function stream() {
var active = true;
var count = 0;
var loop = function () {
if (!active) return;
count++;
@robey
robey / perf.js
Created June 21, 2015 15:16
home-built version of jsperf
#!/usr/bin/env node
// determine how many rounds beats 100ms
function calibrate(name, f) {
console.log("Calibrating " + name + " ...");
var rounds = 1, done = false, startTime, endTime;
while (!done) {
rounds *= 10;
startTime = Date.now();
for (var i = 0; i < rounds; i++) f();
@robey
robey / setup-socks.sh
Created April 4, 2015 17:28
ssh socks proxy
#
# ssh supports socks proxy forwarding, built-in.
#
# on a mac, a socks proxy is setup in:
# System Preferences -> Network -> Advanced -> Proxies -> SOCKS Proxy
# chrome, at least, supports this by default. make sure, in "advanced settings",
# it says something like:
# "Google Chrome is using your computer's system proxy settings to connect
# to the network."
#
@robey
robey / AnnotatedExecutionContext.scala
Created September 26, 2014 17:09
example usage of ExecutionContext.prepare -- would love to know a better way to do this.
/**
* The state (in a hobo bindle) to be carried through the execution context.
*/
protected final case class Bindle(requestId: String, tracing: Boolean)
object AnnotatedExecutionContext {
private val localBindle = new ThreadLocal[Bindle]()
private val localExecutionContext = new ThreadLocal[AnnotatedExecutionContext]() {
override def initialValue() = new AnnotatedExecutionContext(ExecutionContext.Implicits.global)
}
@robey
robey / post_errors.scala
Last active August 29, 2015 14:06
My totally hacky fix for a bug in scala futures where RejectedExecutionException is not used to complete a promise.
// patch up case where scala might not complete a future when the thread-pool is full.
// [Promise.scala:40](https://github.com/scala/scala/blob/v2.10.4/src/library/scala/concurrent/impl/Promise.scala#L40)
override def prepare = new ExecutionContext {
val context = wrapped.prepare
var wasRunning: Option[Runnable] = None
def execute(runnable: Runnable) {
wasRunning = Some(runnable)
context.execute(runnable)
@robey
robey / patchref.c
Created July 13, 2014 04:16
mmap a block of memory as read-only, attempt to write to it, catch the SEGV, fix up the address, and restart the instruction. darwin.
void sighandle(int signal, struct __siginfo *siginfo, void *unused) {
ucontext_t *uc = (ucontext_t *)unused;
int reg_count = sizeof(uc->uc_mcontext->__ss) / sizeof(uint64_t);
uint64_t *reg_table = (uint64_t *)&uc->uc_mcontext->__ss;
for (int i = 0; i < reg_count; i++) {
printf("reg%d: %llx\n", i, reg_table[i]);
if (reg_table[i] == uc->uc_mcontext->__es.__faultvaddr) {
printf("PATCHING to %p\n", &whatever);
reg_table[i] = (uint64_t)&whatever;
}
@robey
robey / config.fish
Last active August 29, 2015 14:01
my basic fish config
#
# fish config file
#
function fish_greeting
echo (set_color 0b0)f(set_color 0b2)i(set_color 0a4)s(set_color 0a8)h(set_color 0aa) \>(set_color 08c)\<(set_color 09f)\>(set_color normal)
end
function fish_title
echo (basename $PWD)/
end

2013 best tweets