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 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!
@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'
@stormbrew
stormbrew / cdo.sh
Last active December 27, 2015 10:29
# 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}"
"$@"
)
}
#include <vector>
template <typename T>
void blah(T) {}
template <typename T>
std::vector<T> blorp(T) {
std::vector<T> x;
return x;
}
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\]"
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 */
}
Python object model in a nutshell (with deliberate errors for simplicity):
- A class is a dict
- The dict contains methods (not in python syntax):
cls = { 'a': function(self, blah) {...}, 'b': function(self, blorp) {...} }
- An object is also a dict that contains an __class__ member that points to the class:
obj = { '__class__': cls }
- When you fetch a method from obj:
obj.a
it looks on __class__ for 'a', and finding it wraps it in a functor that adds the self parameter:
function(blah) { obj['__class__']['a'](obj, blah) }
#include <string>
#include <cstdio>
using namespace std;
class X
{
public:
string str;
X(const string &s) : str(s) { printf("Constructor %s 0x%p\n", str.c_str(), this); }
~X() { printf("Destructor %s 0x%p\n", str.c_str(), this); }
@stormbrew
stormbrew / gist:2521852
Created April 28, 2012 20:39
Devil's advocate argument for case based on its term-less form
# Ugly poorly aligned if
if a == b
elsif b == c
elsif z == d
else
end
#include <stdio.h>
int my_atoi(const char *str)
{
int neg = 1;
int x = 0;
if (*str == '-')
{
neg = -1;
*str++;