Skip to content

Instantly share code, notes, and snippets.

@mdawaffe
mdawaffe / diff-changed-lines.sh
Last active October 4, 2023 08:38
Get line numbers of changed lines - git, diff - Full of bashisms
#!/bin/bash
# Call like you would `diff`
# `./diff-changed-lines.sh old new`
# Outputs the lines numbers of the new file
# that are not present in the old file.
# That is, outputs line numbers for new lines and changed lines
# and does not output line numbers deleted or unchanged lines.
@mdawaffe
mdawaffe / instructions
Created September 1, 2023 23:24
Statically Compiling Nano
# I was targeting a machine using this version of Debian. Hopefully, you're targeting something newer.
docker run --rm -it debian:stretch bash
# This version of Debian is old enough that the package list has been moved to the archives.
# You may not need to do this.
# Note: if you're using a backports distribution, you'll need to do the same for /etc/apt/sources.list.d/*
sed -i s/deb.debian.org/archive.debian.org/g /etc/apt/sources.list
apt update # Some errors. Seems fine?
# aptitude is easier to use if there are problems/conflicts.
@mdawaffe
mdawaffe / Readme.md
Last active September 1, 2023 06:14
Strip HTML markup from a string.

Strip Tags

Strip HTML tags from a string. Does not use (much) regex.

Never loads any resources (<img>, <script>, etc.) referenced in the input.

The treatment of whitespace is probably consistent across browsers but is not guaranteed.

Technique

@mdawaffe
mdawaffe / moon.sh
Created December 5, 2013 02:09
Express the Current Approximate Phase of the Moon as an Emoji Character in UTF-8
#!/bin/bash
# Approximates the phase of the moon using a known new-moon time and a fixed lunar phase of 2551443 seconds.
# Outputs the phase as an emoji in UTF-8
CHARS=(
"\xf0\x9f\x8c\x91" # 0 - NEW
"\xf0\x9f\x8c\x91" # 1 - NEW
"\xf0\x9f\x8c\x92" # 2 - WAXING CRESCENT
@mdawaffe
mdawaffe / Readme.md
Last active August 1, 2017 03:45
Print Trinet/HR Passport Paystubs

Trinet Paystubs

Prints all your paystubs from Trinet one by one. When saving PDFs, the date is used as the filename.

To Use

  1. Log in to HR Passport.
  2. Myself → My Payroll → Earnings Statements
  3. (Click "View All Paychecks" at the bottom of the page if such a link exists)
@mdawaffe
mdawaffe / .gitignore
Last active January 25, 2017 05:08
Gmail OAuth2 Transport for Nodemailer
config.json
.credentials
node_modules
@mdawaffe
mdawaffe / socks4.py
Created December 2, 2013 03:01
SOCKS4 Experiments Failed attempts at restricting a Socks 4/4a/5 proxy to only use Socks 4
#!/usr/bin/env python
import socket
import threading
import select
import SocketServer
class TCPServer( SocketServer.TCPServer ):
allow_reuse_address = True
@mdawaffe
mdawaffe / arrow-keys.sh
Created December 2, 2013 02:42
Terminal Arrow Keys Experiment
#!/bin/bash
ENTER=$(printf "%b" "\n")
ESCAPE=$(printf "%b" "\e")
UP_SUFFIX="A"
DOWN_SUFFIX="B"
RIGHT_SUFFIX="C"
LEFT_SUFFIX="D"
while true; do
@mdawaffe
mdawaffe / arrow-keys.sh
Created December 2, 2013 02:42
Terminal Arrow Keys Experiment
#!/bin/bash
uparrow=$'\x1b[A'
downarrow=$'\x1b[B'
leftarrow=$'\x1b[D'
rightarrow=$'\x1b[C'
read -s -n3 -p "Hit an arrow key: " x
case "$x" in
@mdawaffe
mdawaffe / mardi-gras.sh
Last active October 22, 2015 05:55
Calculates the Date of Mardi Gras from `ncal -e`
#!/bin/bash
function usage {
echo "$0 [-n NUMBER] [YEAR]"
}
date -j &> /dev/null
if [ $? -eq 0 ]; then
# OS X
function mardigras {