Skip to content

Instantly share code, notes, and snippets.

View zaz's full-sized avatar

Zaz Brown zaz

View GitHub Profile
\documentclass[a4paper]{article}
\usepackage{multicol, amsmath, amsfonts, xcolor}
\usepackage[landscape, margin=0.2in]{geometry}
\title{15.415 Cheat Sheet}
\author{Zaz Brown}
\date{Dec 2021}
\newcommand{\dd}{\mathrm d}
\documentclass[a4paper]{article}
\usepackage{multicol, amsmath, amsfonts, xcolor}
\usepackage[landscape, margin=0.2in]{geometry}
\title{15.415 Cheat Sheet}
\author{Zaz Brown}
\date{Dec 2021}
\newcommand{\dd}{\mathrm d}
@zaz
zaz / git-replace-author
Last active September 23, 2018 09:41
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.
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 December 17, 2015 04:20
A simple solution to FizzBuzz — Clojure
(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 January 2, 2023 21:51
Dijkstra's algorithm — Python. Deprecated: Find the updated version at https://github.com/zaz/dijkstra
# 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 = {}

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:

@zaz
zaz / example-1.rb
Last active August 29, 2015 14:07 — forked from thatrubylove/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 July 12, 2014 16:12
Connect to a router by its MAC address (static IP).
#!/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 December 15, 2015 13:09
Collection of jQuery scripts.
$(".email").each(function() {
$(this).html( $(this).html().replace("...", "@").replace(/\.\.\./g, ".") );
$(this).attr("href", $(this).attr("href").replace("...", "@").replace(/\.\.\./g, ".") );
});
@zaz
zaz / bashrc
Created July 30, 2010 20:59
miscellaneous configs
# 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