Skip to content

Instantly share code, notes, and snippets.

View stormbrew's full-sized avatar

stormbrew stormbrew

  • Edmonton, Alberta, Canada
View GitHub Profile
@stormbrew
stormbrew / .i3config
Created April 6, 2016 21:43
i3wm ctrl-p for window switching
bindsym $mod+o exec i3-msg '[id='$(i3-msg -t get_tree | jq -r 'recurse(.nodes[]) | select(.window) | (.window | tostring) + ":" + .name' | ~/.config/bin/dmenu_map -i)'] focus'
bindsym $mod+Mod1+o exec i3-msg '[id='$(i3-msg -t get_tree | jq -r 'recurse(.nodes[]) | select(.window and .urgent) | (.window | tostring) + ":" + .name' | ~/.config/bin/dmenu_map -i)'] focus'
#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
}

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:

def surprising_case(*a)
case
when *a
true
else
false
end
end
surprising_case(false, false, false) # => false
@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 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
#!/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 $?; }
@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
@stormbrew
stormbrew / .i3config
Created March 18, 2014 07:53
my i3wm.conf
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout somewhen, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
# 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):
#