Skip to content

Instantly share code, notes, and snippets.

View jlp78's full-sized avatar

Jan Peterson jlp78

View GitHub Profile
@jlp78
jlp78 / monty.pl
Last active February 13, 2024 23:44
Simple implementation of the statistics Monty Hall problem.
#! /usr/bin/perl
# implement the monty hall problem, run it a while, calculate percentages
sub make_doors {
my($car, @door, $i);
$car = int(rand(3));
for ($i = 0; $i < 3; $i++) {
$door[$i] = ($i == $car);
@jlp78
jlp78 / expandurl.sh
Last active February 14, 2024 11:03
# from Aaron Toppence (eightyeight) https://ae7.st/p/734
# updated to detect if TOR is not running
expandurl () {
(torsocks wget --spider -O - -S $1 2>&1 |
awk '/^Location/ {gsub("\\?utm_.*$",""); print $2; exit 0}
/socks5 libc connect: Connection refused/ {exit 1}') ||
(echo "warning, TOR not enabled"
wget --spider -O - -S $1 2>&1 |
awk '/^Location/ {gsub("\\?utm_.*$",""); print $2; exit 0}')
}
@jlp78
jlp78 / eject.sh
Last active February 14, 2024 11:05
functions to assist in managing mounted devices on Mac OS X
eject () {
case "x$1" in
x)
disk=`osascript -e 'tell application "Finder" to get name of every disk whose ejectable is true' 2>/dev/null |
perl -ne 'print((split(", "))[0], "\n");'`
;;
*)
disk="$1"
;;
esac

Keybase proof

I hereby claim:

  • I am jlp78 on github.
  • I am jlp78 (https://keybase.io/jlp78) on keybase.
  • I have a public key ASA4GlL9W7ntCovvwzSCNXFXgrRSJpTl3YOps3_2Ki368Ao

To claim this, I am signing this object:

@jlp78
jlp78 / increment.py
Last active April 14, 2018 22:48
increment a string (i.e. "A" => "B", "Z" => "AA", "AA" => "AB", etc.) in Python (in Perl, assuming "A" is in $s, it's $s++)
# lifted from http://bit.ly/2iJfRou (codereview.stackexchange.com)
# yeah, I can't believe how painful this is in Python. Perl's auto-incrementing
# strings have this beat by a mile.
def incr_chr(c):
return chr(ord(c) + 1) if c != 'Z' else 'A'
def incr_str(s):
lpart = s.rstrip('Z')
num_replacements = len(s) - len(lpart)
new_s = lpart[:-1] + incr_chr(lpart[-1]) if lpart else 'A'