Skip to content

Instantly share code, notes, and snippets.

@rgov
rgov / curl2requests.py
Created June 18, 2018 03:53
Convert a CURL command line to the equivalent Python Requests invocation
#!/usr/bin/env python
import argparse
import pprint
import shlex
import urllib
# Lex the curl command into its constituent arguments
example = '''
curl 'http://seethroughny.net/tools/required/reports/payroll?action=get' \
import itertools, struct, sys
inout = '''
2bf256b8 02df1f6d04e4
5bfe5eb8 32eb276d54f8
ab315fb8 821e286d84a5
cbe057b8 a2cd206de4da
db391710 b226e0c5d4bd
dbb457b8 b2a1206dd426
a506b5a2 7cf37e578ef0
$ brew install --build-from-source -v imagemagick
/usr/bin/sandbox-exec -f /tmp/homebrew20180331-53954-9qs2b3.sb nice /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -W0 -I /usr/local/Homebrew/Library/Homebrew -- /usr/local/Homebrew/Library/Homebrew/build.rb /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/imagemagick.rb --verbose
==> Downloading https://dl.bintray.com/homebrew/mirror/imagemagick-7.0.7-28.tar.xz
Already downloaded: /Users/rzg/Library/Caches/Homebrew/imagemagick-7.0.7-28.tar.xz
==> Verifying imagemagick-7.0.7-28.tar.xz checksum
tar xJf /Users/rzg/Library/Caches/Homebrew/imagemagick-7.0.7-28.tar.xz
==> ./configure --disable-osx-universal-binary --prefix=/usr/local/Cellar/imagemagick/7.0.7-28 --disable-dependency-tracking --disable-silent-rules --enable-shared --enable-static --with-modules --enable-opencl --enable-openmp --without-webp --without-openjp2 --without-gslib --with-gs-font-dir=/usr/local/share/ghostscript/fonts --without-fftw --without-pango --witho
'''
Use the IP_BOUND_IF socket option to bind to a specific network interface on macOS.
'''
import socket
IP_BOUND_IF = 25
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.IPPROTO_IP, IP_BOUND_IF, socket.if_nametoindex('en0'))
def unrolled(key, nonce):
h = [0]*16
h[0] = 25*key[10] + 10*key[11] + 8*key[12] + 13*key[13] + 19*key[14] + 16*key[15] + 13*key[1] + 13*key[2] + 10*key[3] + 13*key[4] + 10*key[5] + 20*key[6] + 16*key[7] + 16*key[8] + 4*key[9] + 10*nonce[10] + 13*nonce[11] + 13*nonce[12] + 12*nonce[13] + 8*nonce[14] + 0*nonce[15] + 5*nonce[1] + 5*nonce[2] + 0*nonce[3] + 5*nonce[4] + 18*nonce[5] + 10*nonce[6] + 12*nonce[7] + 7*nonce[8] + 12*nonce[9] + 23
h[1] = 19*key[10] + 20*key[11] + 11*key[12] + 4*key[13] + 16*key[14] + 11*key[15] + 5*key[1] + 5*key[2] + 14*key[3] + 5*key[4] + 0*key[5] + 0*key[6] + 5*key[7] + 25*key[8] + 7*key[9] + 12*nonce[10] + 16*nonce[11] + 22*nonce[12] + 14*nonce[13] + 13*nonce[14] + 5*nonce[15] + 18*nonce[1] + 18*nonce[2] + 0*nonce[3] + 18*nonce[4] + 24*nonce[5] + 22*nonce[6] + 2*nonce[7] + 20*nonce[8] + 2*nonce[9] + 11
h[2] = 11*key[10] + 21*key[11] + 12*key[12] + 18*key[13] + 11*key[14] + 20*key[15] + 25*key[1] + 25*key[2] + 10*key[3] + 25*key[4] + 24*key[5] + 22*key[6] +
#!/usr/bin/env python3
import itertools
import string
from base64 import urlsafe_b64decode
ct = '''
fKEMBn_JdCE
t47sBiy2lfo
2-JuV-XQgjM
@rgov
rgov / apeman_merge.py
Created February 11, 2018 06:02
A script for merging and transcoding sequences of videos produced by the Apeman action camera
#!/usr/bin/env python3
'''
My Apeman-branded action camera for some reason splits videos across many
different MP4 files, each lasting only a few minutes. This script handles
merging these videos back together. It can automatically separate multiple
sequences in the same args.directory.
Requires FFmpeg (with the ffprobe tool). If FFmpeg is built with H.265 support,
this script can also transcode the video with the --hevc option.
'''
#!/usr/bin/env python
import acme.client
import acme.messages
# The acme.jose module will soon be split off into a separate package called
# josepy. Until acme is updated, we need to continue using acme.jose.
try:
import acme.jose as josepy
except ImportError:
@rgov
rgov / .block
Created December 12, 2017 01:36 — forked from mbostock/.block
Poisson-Disc
license: gpl-3.0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
This module attempts to implement syllabification for Greek words.
The consonant clusters are derived from "Greek: A Comprehensive Grammar of the
Modern Language" by D. Holton, et al.
'''