Skip to content

Instantly share code, notes, and snippets.

#!/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 ~
@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 / 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 / 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>
#!/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"
@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 / filesink.rb
Last active November 7, 2017 00:39
Blather XMPP bot that receives file transfers that are sent using XEP 0096. Not at all complete, but wanted to post something that demonstrates working file transfer, since I couldn't find any.
require 'rubygems'
require 'blather/client'
require 'awesome_print'
require 'nokogiri'
require 'pretty-xml'
require 'nokogiri-pretty'
include PrettyXML
# This is a Blather bot that receives file transfers that are sent using
# XEP 0096, using either p2p SOCKS5 (XEP 0065), or through the server
@dreness
dreness / schmoVids.py
Last active December 17, 2017 00:44
Somebody asked what their second-longest video is :)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import isodate
import time
import math
import json
import sys
import os
from ytdata import YTData
from datetime import datetime
@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
"""
@dreness
dreness / funcs.sh
Created February 11, 2018 01:44
a few bash techniques for error handling
#!/usr/bin/bash
trap "echo inner ERR" ERR
trap "echo inner EXIT" EXIT
aThunk()
{
unsurprisingly
}