Skip to content

Instantly share code, notes, and snippets.

@dreness
dreness / throttle.sh
Last active December 30, 2022 17:59
A script to apply bandwidth limits to specific traffic in OS X using pf and dummynet
#!/bin/bash
# Create a file such as /Users/you/Documents/pftable to hold a list of IPs or subnets to throttle.
# Example file contents:
# 1.2.3.4
# 2.3.4.5/16
# Reset dummynet to default config
dnctl -f flush
@dreness
dreness / recent-attachments.sql
Last active June 6, 2022 00:17
Show recent file attachments from Message.app's chat DB
-- sqlite3 ~/Library/Messages/chat.db < recent-attachments.sql
-- dates in the DB are NSDate. NSDate.h says: NSTimeIntervalSince1970 978328800
select
Datetime(
created_date + strftime("%s", "2001-01-01"),
"unixepoch",
"localtime"
) as created,
mime_type,
@dreness
dreness / attachments-for-buddy.sql
Last active June 24, 2020 15:52
List all #iMessage attachments associated with a given buddy
-- sqlite3 ~/Library/Messages/chat.db < attachments-for-buddy.sql
-- dates in the DB are NSDate. NSDate.h says: NSTimeIntervalSince1970 978328800
-- To list attachments for a specific buddy, put their handle in the 'where' clause at the end.
SELECT Datetime(created_date + 978328800, 'unixepoch', 'localtime'),
mime_type,
total_bytes,
filename
FROM attachment
@dreness
dreness / pre-commit
Last active June 22, 2021 13:55
#git pre-commit #hook to set commit email address based on the repo's remote domain(s)
#!/bin/zsh
#
# Set repo's user.email to a default or alternate value based on remote domain.
# Because the in-flight commit info has already been set, if an email address
# change is needed, this commit is aborted. Retry the commit to use the new address.
#
# To automatically install custom hooks to new repos:
# 1) Add something like the following to ~/.gitconfig:
# [init]
# templatedir = ~/.git/templates
@dreness
dreness / dezalgo.php
Last active February 25, 2016 22:27
exorcise the mind of zalgo from a text file
## install composer
# mkdir dezalgo ; cd dezalgo
## place dezalgo.php (this file) into the new directory
# composer require mdwheele/zalgo
# php dezalgo.php --infile MyBestIRCLog --outfile MySafeIRCLog
<?php
require __DIR__ . '/vendor/autoload.php';
use Zalgo\Mood;
use Zalgo\Soul;
@dreness
dreness / fix-aifc.sh
Last active May 7, 2022 18:52
Attempt to repair an interrupted QuickTime Player audio recording
#!/bin/zsh
# https://gist.github.com/dreness/e61fb16dcb831adaf6ff
# dre@mac.com
#
# This script attempts to repair Quicktime Player audio recordings
# that become broken when Quicktime Player is interrupted while recording.
# AIFC files can be recovered with no additional help, however to recover
# M4A files, you also need the 'faad' command line tool.
@dreness
dreness / manual-ocsp-check.txt
Last active May 7, 2020 22:48
Manually check #codesigning #certificate revocation status using OCSP
# Assumes an Apple-like layout: leaf --> issuer --> CA in exactly 3 certs
# The last arg to codesign specifies the code to check, by bundle or executable path, or process ID
codesign -d -vv --extract-certificates=cert I-didnt-edit-my-config-file
for i in 0 1 2 ; do openssl x509 -inform der -in cert${i} -out cert${i}.pem ; done
openssl ocsp -CAfile cert2.pem -issuer cert1.pem -cert cert0.pem -url $(openssl x509 -in cert0.pem -ocsp_uri -noout)
Example:
╭─ andre@flux ~
@dreness
dreness / keybase.md
Created March 23, 2016 18:23
keybase proof

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

#!/bin/bash
# extra verbose
set -x
# sync mods from local host to remote host (e.g. a minecraft server)
# optionally delete extraneous files in the remote mods directory
# Go home to allow relative paths below, but remember current dir.
pushd ~
#!/usr/bin/python
import json
import urllib2
from pprint import pprint
# These URLs are discovered by viewing https://developer.apple.com/wwdc/live/#/
# and using the web inspector to find the wwdc-streaming javascript.
# Currently: https://developer.apple.com/wwdc/live/scripts/app/min/wwdc-streaming-0.1.0.min.js
# Search that javascript for "videos.json" and "videos_live.json"