Skip to content

Instantly share code, notes, and snippets.

Avatar

Zaz Brown zaz

View GitHub Profile
View 15.455_QuantFin_cheatsheet.tex
\documentclass[a4paper]{article}
\usepackage{multicol, amsmath, amsfonts, xcolor}
\usepackage[landscape, margin=0.2in]{geometry}
\title{15.455 Cheat Sheet}
\author{Zaz Brown}
\date{Sep 2021}
\newcommand{\dd}{\mathrm d}
@zaz
zaz / git-replace-author
Last active Sep 23, 2018
If you accidentally make some commits with your email (or name) set incorrectly, this script fixes it. With no arguments, it updates all commits with your name to use your email address according to Git config. Don't use this on a branch you're collaborating on.
View git-replace-author
DEFAULT_NAME="$(git config user.name)"
DEFAULT_EMAIL="$(git config user.email)"
export OLD_NAME="${1:-$DEFAULT_NAME}"
export NEW_NAME="${2:-$DEFAULT_NAME}"
export NEW_EMAIL="${3:-$DEFAULT_EMAIL}"
echo "Old:" $OLD_NAME "<*>"
echo "New:" "$NEW_NAME <$NEW_EMAIL>"
echo "To undo, use: git reset $(git rev-parse HEAD)"
@zaz
zaz / fizzbuzz.clj
Last active Dec 17, 2015
A simple solution to FizzBuzz — Clojure
View fizzbuzz.clj
(defn fizzbuzz?
"Determines what to print for a given number"
[x]
(condp #(zero? (mod %2 %1)) x
15 "fizzbuzz"
3 "fizz"
5 "buzz"
1 x))
(defn fizzbuzz
@zaz
zaz / dijkstra.py
Last active Nov 23, 2020
Dijkstra's algorithm — Python
View dijkstra.py
# Zaz Brown
# github.com/zaz/dijkstra
"""An efficient algorithm to find shortest paths between nodes in a graph."""
from collections import defaultdict
class Digraph(object):
def __init__(self, nodes=[]):
self.nodes = set()
self.neighbours = defaultdict(set)
self.dist = {}
View keybase.md

Keybase proof

I hereby claim:

  • I am jb on github.
  • I am ht (https://keybase.io/ht) on keybase.
  • I have a public key whose fingerprint is 3582 E1C0 B987 41E8 CD01 F6B9 419C A53B DF3C B6C3

To claim this, I am signing this object:

View example-1.rb
numbers = [1,3,5,8,10,54,99]
cards = [5,3,4,6,2]
# get only the values where the distance is greater than 10
numbers.each_cons(2).select {|a,b| b-a>10 } #=> [[10, 54], [54, 99]]
# determine if the hand is a straight
cards.sort.each_cons(5).all? do |series|
series.last - series.first == 4
end #=> true
@zaz
zaz / connectMAC
Created Jul 12, 2014
Connect to a router by its MAC address (static IP).
View connectMAC
#!/bin/bash
DEV="eth0"
ROUTER="192.168.0.1"
MAC="${1:-01:23:45:67:89:ab}"
IP="192.168.0.5/24"
if [[ "${UID}" != 0 ]]; then
exec sudo "$0" $@
fi
@zaz
zaz / email-de-obfuscator
Last active Dec 15, 2015
Collection of jQuery scripts.
View email-de-obfuscator
$(".email").each(function() {
$(this).html( $(this).html().replace("...", "@").replace(/\.\.\./g, ".") );
$(this).attr("href", $(this).attr("href").replace("...", "@").replace(/\.\.\./g, ".") );
});
@zaz
zaz / bashrc
Created Jul 30, 2010
miscellaneous configs
View bashrc
# Check for an interactive session:
[ -z "$PS1" ] && return
# Bash prompt: user@HOST [ dir ] $
PS1='\[\e[1;32m\]\u@\h [ \[\e[31m\]\w\[\e[32m\] ]$(__git_ps1 " [\[\e[31m\]%s\[\e[32m\]]" 2>/dev/null) \$ \[\e[0m\]'
#PS1='\[\u@\h [ \w ]$(__git_ps1 " (%s)" 2>/dev/null) \$ ' # Black & White
# History file:
shopt -s histappend
HISTCONTROL=ignoredups:ignorespace