Skip to content

Instantly share code, notes, and snippets.

@marczych
marczych / gist:10524654
Last active August 29, 2015 13:59
Tmux git-scripts functions
#!/bin/sh
# Convenience functions to set the tmux session name based on branches/pull
# numbers and switches branches based on the session name.
#
# Depends on tmux and https://github.com/iFixit/git-scripts.
# (feature|hotfix) switch based on the session name.
function tswitch {
BRANCH=$(tmux display-message -p '#S' | sed 's/|.*$//')
@kohsuke
kohsuke / git-children-of
Created November 21, 2013 21:44
Given a commit, find immediate children of that commit.
#!/bin/bash -e
# given a commit, find immediate children of that commit.
for arg in "$@"; do
for commit in $(git rev-parse $arg^0); do
for child in $(git log --format='%H %P' --all | grep -F " $commit" | cut -f1 -d' '); do
git describe $child
done
done
done
@danielbeardsley
danielbeardsley / README.md
Last active December 20, 2015 10:59
A bash script to temporarily slow down your intertubes on MacOS.

slow-it-down

Simulate a slow network connection with one command.

Turn on:

$> sudo ./slow-it-down
Your tubes are now filled with molasses
@jeremyjarrell
jeremyjarrell / Idempotent migration in MySQL example
Created July 25, 2013 20:06
In MySQL, IF statements cannot exist outside of stored procedures. Therefore, to create an idempotent migration for MySQL it's necessary to wrap the migration in a stored procedure and execute that stored procedure against the database to perform the migration.
DELIMITER $$
DROP PROCEDURE IF EXISTS add_email_address_column_to_customers_table $$
-- Create the stored procedure to perform the migration
CREATE PROCEDURE add_email_address_column_to_customers_table()
BEGIN
-- Add the email_address column to the customers table, if it doesn't already exist
// Yields the approximate result of a division by 1000.
// NOTE: Can only be used for numbers less than 140,737,488,290
unsigned long quickDiv1000(unsigned long num)
{
unsigned long result;
result = num * 65 + (num >> 2) + (num >> 5) + (num >> 8)+ (num >> 11) + 32768;
return (result >> 16);
}

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@jtdreisb
jtdreisb / Makefile
Created February 13, 2012 00:20
utility that syncs an arbitrary bundle id's prefs
CC = clang
CFLAGS = -Wall -g
LDFLAGS = -framework CoreFoundation
TARG = syncdefaults
SRC=\v
syncdefaults.c\
@sontek
sontek / snowjob.sh
Last active April 5, 2024 06:51
Make your terminal snow
#!/bin/bash
LINES=$(tput lines)
COLUMNS=$(tput cols)
declare -A snowflakes
declare -A lastflakes
clear