Skip to content

Instantly share code, notes, and snippets.

@jaysoffian
jaysoffian / remerge
Created May 6, 2012 13:06
A script for rebasing a merge
#!/bin/sh -x
# remerge <onto> [<merge_commit>]
# e.g.: remerge origin/trunk
# merge_commit defaults to HEAD
onto=$1
mc=${2:-HEAD}
mc_sha=$(git rev-parse $mc) # original merge commit
p1_sha=$(git rev-parse $onto) # what we want its new first parent to be
@jaysoffian
jaysoffian / gist:7bb70e1065f085b46a00
Created April 26, 2011 18:15
network calculator in awk
netfn () {
echo "$1" |
awk 'function nto32b(n){ # converts an integer to a 32-bit ascii bitstring
b=""
while (n>1) {
if (n%2) {b="1"b} else {b="0"b}
n=int(n/2)
}
b="1"b
return sprintf("%032s",b)
@jaysoffian
jaysoffian / kurosawa_top_100.py
Created March 23, 2021 17:59
Convert Akira Kurosawa's top 100 films to a CSV for import to Letterboxd
#!/usr/bin/python3
"""
Convert Akira Kurosawa's top 100 films to a CSV for import to Letterboxd.
List extracted from https://www.openculture.com/2015/01/akira-kurosawas-list-of-his-100-favorite-movies.html
"""
LIST = """
1. Broken Blossoms or The Yellow Man and the Girl (Griffith, 1919) USA
@jaysoffian
jaysoffian / git-lost-and-found
Last active July 15, 2022 21:30
"git lost-and-found" command to help recover objects you added but failed to commit and then deleted by accident
#!/bin/sh
find .git/objects -mtime -2h -type f | while read -r path
do
dir=${path#.git/objects/}
dir=${dir%/*}
name=${path##*/}
id=$dir$name
type=$(git cat-file -t "$id")
if test "$type" = blob
then
@jaysoffian
jaysoffian / gem-install.sh
Last active March 29, 2023 23:02
A script to install one or more gems in a self-contained directory, similar to installing Python packages in a virtual environment
Replaced by gem-venv.sh.
Please see https://gist.github.com/jaysoffian/3c67711d3f00c364365905d877cc4af4 instead.
@jaysoffian
jaysoffian / gem-venv.sh
Last active October 29, 2023 00:13
Like a Python venv, but for installing Ruby gems
#!/bin/bash
# gem-venv.sh
# ~~~~~~~~~~~
# Summary: Like a Python venv, but for installing Ruby gems.
#
# Create a directory and gem wrapper script for installing gems self-contained
# to that directory. Control which `gem` is used via the `-G/--gem` switch,
# defaulting to whatever `gem` is found in PATH.
#
# Optionally takes a list of gems to install using the just created directory