Skip to content

Instantly share code, notes, and snippets.

View analogist's full-sized avatar

James Wu analogist

View GitHub Profile
@analogist
analogist / get_follows_lookup.py
Last active November 18, 2022 02:12
Saves Twitter follows and their account profiles
import tweepy
import json
username = YOUR_USERNAME_HERE
auth = tweepy.OAuth1UserHandler(
# CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET
)
api = tweepy.API(auth)
@analogist
analogist / echopickle.py
Created January 7, 2022 22:36
display contents of a pickle
import sys, pickle
with open(sys.argv[1], 'rb') as f:
print(pickle.load(f))
@analogist
analogist / bom_audio_switch_4in_1out.csv
Created March 31, 2021 19:01
BOM for a 4-in, 1-out 3.5mm stereo audio switch (2 stereo in, 2 mono inputs) and potentiometer volume control
Index Quantity Part Number Manufacturer Part Number Description Customer Reference Backorder Unit Price Extended Price
1 2 839-1410-ND 54-00080 CONN JACK PNL MNT 3.5MM MONO 0 2.52000 $5.04
2 3 839-1411-ND 54-00081 CONN JACK PNL MNT 3.5MM STEREO 0 2.52000 $7.56
3 1 53AAA-B28-A10L-ND 53AAA-B28-A10L POT 1K OHM 1W CERMET LINEAR 0 8.76000 $8.76
4 1 CKN10623-ND A30405RNZQ SWITCH ROTARY 4POS 2.5A 125V 0 8.90000 $8.90
5 1 679-3545-ND MPKES90B14 KNOB FLUTED W/SKIRT 0.250" PLAST 0 2.18000 $2.18
6 1 450-1742-ND PKG50B1/4 KNOB RIBBED 0.250" PLASTIC 0 2.41000 $2.41
Subtotal $34.85
function cryptoRandomInt(min, max, num=1) {
if (!Number.isInteger(min))
throw("min should be an integer");
if (!Number.isInteger(max))
throw("max should be an integer");
if (!Number.isInteger(num))
throw("num should be an integer");
if (num < 1)
throw("num should be 1 or greater");
if (min >= max)
@analogist
analogist / randint.sh
Created January 12, 2020 05:39
unbiased arbitrary random integer generator using kernel cryptographic random
randint ()
{
# Generate unbiased integers between arbitrary ranges using kernel cryptographic random
# check for invalid arguments
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]
then
echo "Usage: randint [MAXINT]"
@analogist
analogist / gist:fff9576d90de9db2d4621884bb37f892
Created November 23, 2019 19:03
PM 2.5 to AQI conversion snippet
double aqi(double x) {
if (x <= 12.0) {
return x / 12.0 * 50.0;
} else if (x > 12.0 && x <= 35.4) {
return (x - 12.0) / 23.4 * 50.0 + 50.0;
} else if (x > 35.4 && x <= 55.4) {
return (x - 35.4) / 20 * 50.0 + 100.0;
} else if (x > 55.4 && x <= 150.4) {
return (x - 55.4) / 95 * 50.0 + 150.0;
} else if (x > 150.4 && x <= 250.4) {
git clone --bare https://github.com/analogist/dotfiles.git $HOME/.dotfiles
function dotfile ()
{
git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME $@
}
dotfile config status.showUntrackedFiles no
if [ -f ~/.bashrc ]; then
mv ~/.bashrc ~/.bashrc.old
fi
dotfile checkout
@analogist
analogist / convhashcat.sh
Last active October 27, 2017 20:35
Convert output of hashcat benchmark hashrates (first device) into relative bit strengths on log2 scale, then subtracts off baseline (coded as MD5 here) for complexity comparison between algorithms.
#!/bin/bash
gawk '\
/^Hashtype/ { $1=""; printf "%s\t",$0 } \
/^Speed\.Dev\.#1/ { \
switch ($3) { \
case "H/s": \
hashrate = $2; \
break; \
case "kH/s": \
@analogist
analogist / gce_md5convert.sh
Last active April 26, 2022 06:45
Convert Google Cloud Storage gsutil ls -L base64-encoded md5 hash listings to md5sum-compatible hash format
#!/bin/bash
# This awk/sed script looks for "gs://bucket/path/filename" and "Hash (md5)",
# swaps the two (so the hash appears before the file, in the md5sum format),
# cuts out the "gs://bucket/" name, and finally converts the md5 hash
# from base64 to hex. This allows for later off-line file integrity check
# via the standard "md5sum -c".
#
# To use it, either save it as an alias or a shell script, and pipe the
# output of gsutil ls -L through it. For example, save it as "md5convert.sh"
# and then run "gsutil ls -L gs://bucket/path | bash md5convert.sh"

Keybase proof

I hereby claim:

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

To claim this, I am signing this object: