Skip to content

Instantly share code, notes, and snippets.

@dreness
dreness / twisted_web_windows
Last active October 7, 2016 07:26
simple twisted web server on windows
# This is needed because SimpleHTTPServer in the standard python distribution isn't good enough for my use case of
# serving large mp4 files. Pretty much every request fails with a broken pipe.
# Start with the 'babun' package to provide the cli environment, based on cygwin. Python is included.
# http://babun.github.io
# Install virtualenv
pip install virtualenv
# Create and activate virtualenv
@dreness
dreness / kc_items.sh
Last active October 9, 2022 17:08
A hopefully stable listing of identities, keys, and certs found in keychain
#!/bin/bash
function sep { printf -- '-%.0s' {1..80}; echo ''; }
sep ; echo "Identities" ; sep
security find-identity
echo ''
sep ; echo "Keys" ; sep
@dreness
dreness / hls-concat
Created November 14, 2016 03:01
Re-assemble HLS segments
1) If applicable, list available formats for this asset.
youtube-dl -F <url>
... then get URL to m3u8 for selected format
youtube-dl -f <format name> -g <url>
2) Download all the segments in the m3u8. Now you have a bag of transport stream segments.
The file names are probably increasing but not necessarily sequentially.
You can do the download with youtube-dl (which automatically re-assembles the results),
but it doesn't support parallel operation. You might find that parallelizing this download
@dreness
dreness / sa_times.py
Created December 3, 2016 00:18
Properly sort the sa(8) accounting records by time stamp
#!/usr/bin/python
from __future__ import print_function
from datetime import datetime
'''
Display the account records gathered by the sa(8) facility.
from /usr/include/sys/acct.h
or on macOS, /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/sys/acct.h
@dreness
dreness / powerConsumption.py
Last active January 31, 2024 02:41
Display rate of charge / discharge of an Apple laptop battery
#!python
# To use this, you need Python 3 and also the pyobjc module.
# pip install pyobjc
import objc
from Foundation import NSBundle, NSString
import datetime
import time
import sys
@dreness
dreness / symfind.py
Last active September 13, 2017 20:57 — forked from pudquick/symfind.py
Automatic symbol definition discovery for OS X binaries and their linked shared libraries
#!/usr/bin/python
"""Usage: symfind BINARY_PATH SEARCH_STR
symfind automates the usage of otool and nm to attempt to find out which
binary a symbol is defined in that's used within BINARY_PATH's code.
"""
import subprocess, os.path, sys, getopt
@dreness
dreness / ShoutCast-polling.md
Last active July 3, 2017 14:04
A tentative analysis of why Shoutcast is spinning a full CPU core

A Shoutcast process (called sc_serv25, with PID 10213) is using way more CPU than expected for the workload - specifically, 100% of a CPU core. Let's investigate.

$ sudo strace -p 10213 -o ~/sc_serv25_strace.txt -f -t -tt -T
(control-c after a few seconds)

Looking at sc_serv25_strace.txt for weirdness, we notice thread 10221 is very hot. Here's an excerpt:

$ grep 10221 ~/sc_serv25_strace.txt
...
10221 1499065013.244010 poll([{fd=14, events=POLLIN}, {fd=75, events=POLLIN}], 2, 0) = 0 (Timeout) <0.000009>
@dreness
dreness / watch_file.d
Last active July 16, 2020 22:29
Try to find out who is opening, reading from, writing to, deleting a file
#!/usr/sbin/dtrace -s
#pragma D option quiet
#pragma D option switchrate=10hz
/* pass the filename to watch for as the only cli argument */
dtrace:::BEGIN
{
/* double dollar sign to stringify cli arg */
@dreness
dreness / owl.py
Last active January 12, 2018 06:37
Reveal OverwatchLeague video URLs
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Work in progress. For now, just show URLs to m3u8 files of match videos.
To use, first do:
pip install -r requirements.txt
TODO: pre-season VODs were split out by game; season1 VODs contain all games in a match
"""