Skip to content

Instantly share code, notes, and snippets.

View stormbrew's full-sized avatar

stormbrew stormbrew

  • Edmonton, Alberta, Canada
View GitHub Profile
# Run this to get a default autocomplete that, if you press
# tab on an empty prompt it will expand to the first term of
# the last command you ran.
#
# Inspired by http://thechangelog.com/interactive-shell-git/
# where I don't really want to have to go in and out of a mode
# when I don't necessarily know it'll be worth it, but being
# able to skip typing git every command would be nice. This way
# you can go (using their example):
#
@stormbrew
stormbrew / test.cpp
Created March 21, 2014 12:05
So recent versions of C++ kind of let you do something obscene that's very reminiscent of ruby blocks...
template <type tNodeType, typename tLambda>
void when(tLambda func)
{
if (tNodeType == node_type) {
func(*reinterpret_cast<node<tNodeType>*>(&data));
}
}
// this is an obscene hack to let you do something like
// the lambda-using when above, but a bit cleaner if more
#!/usr/bin/env bash
set -o pipefail
# Find the repo, fail if we're not in a git repo or the origin has a weird name.
# TODO: Add other kinds of version control
# TODO: Make the remote name configurable with git config
repo_dir=$(git rev-parse --show-toplevel)
[[ $? != 0 ]] && { echo "Not in a git directory!"; exit $?; }
origin=$(git remote -v | egrep '^origin.+\(fetch\)' | awk '{print $2}')
[[ $? != 0 ]] && { echo "Couldn't find an origin."; exit $?; }
def destructive_merge(a,b)
res = []
while !a.empty? && !b.empty?
while !a.empty? && a.first < b.first
res << a.shift
end
a, b = b, a
end
res
end
@stormbrew
stormbrew / randombytes.php
Last active August 29, 2015 14:03
Twitter algorithmic code review
<?php
function getRandomRangedBytes($length, $max) {
// inspired by: http://stackoverflow.com/a/2999130/3803650
// This safely generates a series of random bytes that are all within
// the range [0,$max) with an even distribution
$divisor = intval(255/$max);
$results = array();
// This looks like it could be a loop that never terminates,
// but that would only be true if openssl was not returning us
def surprising_case(*a)
case
when *a
true
else
false
end
end
surprising_case(false, false, false) # => false

Keybase proof

I hereby claim:

  • I am stormbrew on github.
  • I am stormbrew (https://keybase.io/stormbrew) on keybase.
  • I have a public key whose fingerprint is EBFB DE2E E440 3651 7D36 5BAB A73A 5685 5652 77EF

To claim this, I am signing this object:

#include <system_error>
int main() {
std::error_code x = std::make_error_code(std::errc::no_such_file_or_directory);
printf("%d\n", x != std::errc::no_such_file_or_directory); // Should print 0, does on libstdc++6 < 5. Prints 1 on libstdc++6-5
}
From a3f952616a416480f9f382248c39d0f37b1385b2 Mon Sep 17 00:00:00 2001
From: Graham <graham-storm-git@ript.net>
Date: Thu, 28 Jan 2010 15:46:33 -0700
Subject: [PATCH 1/2] Updated spec for issue when raising an object instance with a message
In MRI, the internal behaviour when passed an object instance as the first argument and a message as the second argument to raise is to clone the object and call the internal (original) initialize on the object. This makes it so that message is set even if the derived initialize doesn't take a message argument.'
---
spec/ruby/language/rescue_spec.rb | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
Program received signal SIGINT, Interrupt.
0x9243046e in __semwait_signal ()
(gdb) bt
#0 0x9243046e in __semwait_signal ()
#1 0x9245b3e6 in _pthread_cond_wait ()
#2 0x9245adcd in pthread_cond_wait$UNIX2003 ()
#3 0x000bc158 in thread::Condition::wait (this=0x4, mutex=@0x4) at thread.hpp:376
#4 0x000e67de in rubinius::Channel::receive_timeout (this=0x22994dc, state=0xf00ee0, duration=0x1a, call_frame=0xbfffd500) at vm/builtin/channel.cpp:122
#5 0x000e6b37 in rubinius::Channel::receive (this=0x4, state=0x4, call_frame=0x4) at vm/builtin/channel.cpp:66
#6 0x00081acf in rubinius::Primitives::channel_receive (state=0xf00ee0, call_frame=0xbfffd500, msg=@0x11c43e0, args=@0xbfffd49c) at primitives_glue.gen.cpp:3949