Skip to content

Instantly share code, notes, and snippets.

View sampsyo's full-sized avatar

Adrian Sampson sampsyo

View GitHub Profile
@sampsyo
sampsyo / lyrics.py
Created August 10, 2011 23:57
Simple dependency-free multi-source lyrics scraper
"""Simple scraper for LyricsWiki and Lyrics.com. The code is hacky and
ugly because I wanted to implement this without a full-blown HTML parser
like BeautifulSoup or lxml.
"""
import urllib
import sys
import re
COMMENT_RE = re.compile(r'<!--.*-->', re.S)
DIV_RE = re.compile(r'<(/?)div>?')
@sampsyo
sampsyo / genres.txt
Created September 25, 2011 23:19
music genre list scraper
2 tone
2-step garage
4-beat
4x4 garage
8-bit
acapella
acid
acid breaks
acid house
acid jazz
@sampsyo
sampsyo / mk2mpris.py
Created July 9, 2012 20:41
forward GNOME media key events to an MPRIS2 player
"""mk2mpris.py: forward GNOME media key events to an MPRIS2 player.
"""
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject
APP_NAME = 'mk2mpris'
DBUS_INTERFACE_MK = 'org.gnome.SettingsDaemon.MediaKeys'
OBJ_PATH_MK = '/org/gnome/SettingsDaemon/MediaKeys'
OBJ_NAME_GSETTINGS = 'org.gnome.SettingsDaemon'
@sampsyo
sampsyo / CopyMachine.java
Created July 31, 2012 19:28
Java object cloning for Jikes RVM
import java.lang.reflect.Array;
import org.vmmagic.unboxed.Address;
import org.vmmagic.unboxed.ObjectReference;
import org.vmmagic.unboxed.Offset;
import org.mmtk.vm.VM;
import org.vmmagic.pragma.Uninterruptible;
import org.jikesrvm.classloader.RVMType;
import org.jikesrvm.runtime.RuntimeEntrypoints;
import org.jikesrvm.runtime.Memory;
@sampsyo
sampsyo / tal.py
Created September 20, 2012 17:42
send This American Life episodes to Huffduffer
#!/usr/bin/env python3
"""Simple scraper for adding This American Life episodes to Huffduffer.
TAL has the most amazing app on the App Store, but some stuff broke on
iOS 6 and it doesn't seem to get bug fixes very often. This is my ad-hoc
solution.
"""
import urllib.request
import urllib.parse
import sys
@sampsyo
sampsyo / config.yaml
Last active January 5, 2016 11:02
trigger/recommendation idea
match:
recommendations:
partial: low
tracknumber: medium
tracklength: medium
@sampsyo
sampsyo / non-mb-thoughs.md
Created May 26, 2013 04:16
thoughts on penalizing non-MB sources

First of all, I like the change that sorts MB candidates above non-MB ones. Thanks for that -- this prioritization definitely seems like something we want to do in general.

Thinking about how to do this kind of thing more generally got me thinking about how the matching logic was originally designed and how we can keep it simple. Specifically, the matching logic gets a lot of simplicity out of segregating the core matching/ranking stuff from the distance components. Because all the comparison stuff is complicated and messy, it's really helpful to have it hidden behind a single abstraction: distance. This also lets us add on new distance components easily without affecting the core logic.

Every time we add new special cases to the ranking and recommendation logic, we break a little bit of this abstraction. That's fine, especially when it brings features that aren't possible otherwise (like the max_rec feature), but for th

@sampsyo
sampsyo / approxcode.py
Created August 1, 2013 23:44
simulate analog storage/transmission errors
import bitstring
import random
import json
# Randomness.
def bernoulli(param):
return random.random() <= param
#!/usr/bin/env python3
import requests
import json
BASE_URL = 'http://www.comicvine.com/api'
API_KEY = 'c7f4481e0a6154b8ac39580747ca8c91c3d4a321'
def dump(jo):
{
"width": 300,
"height": 150,
"data": [
{
"name": "performance",
"values": [
{
"component": "compile",
"prog": "foo",