This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef int AA; | |
void foo() | |
{ | |
AA AA; /* OK - define variable AA of type AA */ | |
int BB = AA * 2; /* OK - AA is just a variable name here */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PS1_LASTEXIT='$(LE=$?; if [ ${LE} -ne 0 ]; then LED=$(perl -le "\$!+=${LE};print \$!"); echo "\[\e[31;1m\]^${LE}:${LED}\[\e[32;1m\]> "; fi)' | |
PS1_USERNAME="\[\e[37;1m\]\u\[\e[32;1m\]> " | |
PS1_JOBS='$(JB=$(jobs -l | wc -l); if [ ${JB} -gt 0 ]; then echo "\[\e[37;1m\]&\j\[\e[32;1m\]> "; fi)' | |
PS1_GIT='$(GPS=$(__git_ps1 %s); if [ -n "${GPS}" ]; then STAT=$(git status --porcelain | cut -c1-2 | sed -E "s/ /-/" | sort | uniq | xargs echo | cut --delimiter=" " -f1- --output-delimiter=","); echo "\[\e[37;1m\]git:${GPS}:\[\e[35;1m\]${STAT}\[\e[32;1m\]> "; fi)' | |
PS1_WD="\[\e[37;1m\]\w\[\e[32;1m\]> " | |
PS1_PROMPTNUM="\[\e[37;1m\]!\!\[\e[32;1m\]" | |
# \! in PS2 actually prints the next command number because the command so far has already been appended to the history. | |
# Instead, get it from fc, which can tell you the last command number. | |
PS2_PROMPTNUM="\[\e[37;1m\]!\$(fc -l -1 | head -1 | awk '{print \$1}')\[\e[32;1m\]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
template <typename T> | |
void blah(T) {} | |
template <typename T> | |
std::vector<T> blorp(T) { | |
std::vector<T> x; | |
return x; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Changes to directory passed in $1 and runs the command specified | |
# by the remaining arguments. | |
function cdo() { | |
at=${1} | |
shift | |
( # enter a subshell to perform the action | |
cd "${at}" | |
"$@" | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 $?; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |