Skip to content

Instantly share code, notes, and snippets.

View ObjectBoxPC's full-sized avatar

Philip Chung ObjectBoxPC

View GitHub Profile
ObjectBoxPC /
Created June 10, 2024 12:46
Print the working directory in a compact form (originally created for tmux status bar customization)
# Print a compact version of the current working directory.
# The home directory is replaced with ~, and long paths are truncated to the final part with < as a marker.
# Examples:
# /home/example/Documents becomes ~/Documents
# /example/of/a/really/really/long/path becomes <ly/really/long/path
# The maximum length can be set using the LIMIT variable.
ObjectBoxPC / anagram.hs
Created October 18, 2023 12:45
Haskell program to check if two inputs (command-line arguments) are anagrams (in terms of the 26 letters in the English alphabet)
import Data.Char (toUpper)
import Data.List (sort)
import System.Environment (getArgs)
import System.Exit (exitWith, ExitCode(..))
data CheckAnagramError = NotEnoughArguments | EmptyInput
isAnagram :: String -> String -> Bool
isAnagram x y = normalize x == normalize y
ObjectBoxPC / sort-prt-bus-schedules.user.js
Last active October 7, 2023 14:28
Userscript to sort Pittsburgh Regional Transit bus schedules numerically
// ==UserScript==
// @name Sort Pittsburgh Regional Transit bus schedules numerically
// @version 2
// @include
// @grant none
// ==/UserScript==
// This script is dedicated to the public domain under Creative Commons CC0 1.0 Universal
// <>
ObjectBoxPC /
Last active June 3, 2024 22:13
Quickly generate random numeric PINs
#!/usr/bin/env python3
# Usage: ./ [number of digits, default 4]
import secrets
import sys
digit_count = int(sys.argv[1]) if len(sys.argv) >= 2 else 4
pin = secrets.randbelow(10**digit_count)
ObjectBoxPC / ruby-regex-word-confusion.txt
Last active February 5, 2023 21:45
Confusion about Ruby Regexp \p{Word} character class
$ ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]
$ irb
irb(main):001:0> /\p{Word}/.match?("\u00B2") # Expected to be true based on description of \p{Word} in Regexp docs
=> false
irb(main):002:0> /\p{Number}/.match?("\u00B2") # U+00B2 is a Number character
=> true
ObjectBoxPC / direct-password-input-treasurydirect.user.js
Last active October 23, 2023 09:02
Userscript to enable direct password input on TreasuryDirect login
// ==UserScript==
// @name Enable Direct Password Input on TreasuryDirect
// @version 1
// @include*
// @grant none
// ==/UserScript==
document.querySelector('input.pwordinput').readOnly = false;
ObjectBoxPC / phishingurl.txt
Last active March 19, 2022 00:45
Analysis of a URL in an Amazon phishing e-mail
# URL in the phishing e-mail is
# Times are UTC-7
$ wget -O /dev/null ''
--2022-03-18 13:30:42--
Resolving (,,, ...
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: [following]
--2022-03-18 13:30:42--
ObjectBoxPC / envelope.tex
Created January 30, 2022 10:23
XeLaTeX template document for printing addresses on envelopes
%Note on rotation: It may be a good idea to rotate the page when printing,
%so that the envelope is in a "portrait" orientation in the printer.
%I tried to use lscape to rotate the text, but that doesn't seem to work with textpos.
%The solution for now is to use an external tool like pdftk
%or the settings in some PDF viewers and printer drivers.
%Suggestions on how to achieve proper rotation in TeX are welcome.
%Envelope dimensions (in inches) (US #10 envelopes are 9 1/2 in. x 4 1/8 in.)
ObjectBoxPC /
Created January 4, 2022 09:00
Quickly generate random passwords using built-in utilities (emulating Python's secrets.token_urlsafe: )
dd if=/dev/urandom bs="$ENTROPY_BYTES" count=1 2> /dev/null | \
base64 -w 0 | sed -e 's/=//g' -e 's/+/-/g' -e 's/\//_/g'
ObjectBoxPC /
Last active January 4, 2022 09:03
Dump payload from a SMART Health Card
# This code is dedicated to the public domain under
# Creative Commons CC0 1.0 Universal <>
import base64
import json
import sys
import zlib
shc = input()