Skip to content

Instantly share code, notes, and snippets.

View sampsyo's full-sized avatar

Adrian Sampson sampsyo

View GitHub Profile
>>> import chromaprint
>>> chromaprint.decode_fingerprint('AQADnpmURJG44mheHKKWZDhxpAOcZ0foDeeF51AkyfAD0i8aHmQeY9KP5g-h60QeLXiCsiExHV_w53iyE1ryBpQeB714TA8a9Th5nAkuW8GV6QmiNkdy_EeZ_WhqB1PUH9X2o-J4NHpy_FpwPwj07chzVNmJSivKRIl0NFeSA8uxT0Wc6EiWKMkd-Id_9BeuXMWVGBdFI6ZzImmkB54e43hYNGGObhuaP6geJE-J-MKTPMK1hPip4AyFonlwTe3wHMmvIufxLLvwFP8Hl3gSJZGKK3sQp_SgC-ld_AqeS-gFj9MRXhQ0xUca8fDya_grPCnSHyLCL8UuHWcOKmFyTAlFtAtL4m3wwL2J_NDxkQiv4Mc_NM9w4krxw19yxA60HH2KXNOPNcGtH8xnFX5Q5senyGAsZfDB8MccbkOCME3soD6OxznKPC18J-jz4MeLh9HxnKgfNE0u_HiQvvihEhFDHXTEY09N_EO-pBz6HFqq_MiZB1d2JfiD-4dfIw-HS9iP72Dk9HgefB9y3LiG18LBI0g4KcVBHcdPOCn6hAef6_iNMx58HfzCB6GTEVpuIfvx6EnwS8N34zmYXMrQ79gXnDlDfNtDWFWSEXeCo33RNPiO3EpC6HPw_IgyHz9xgsmZBEl0WsiP67gQXGJK9El0aIkf5BZ-VMdx4tJwHdsL5sMR8YdGHmFe1FngZMpc-JgYC7kkGXxe6Bh_yDkiRx0P1wlx8DkO98eZMEgeIedwinh2NFWO6TmamEaVOT5-IcwYlOkX6Dlu_HhYCX8GzT_CpMmCZzp-7Dt4zdiTBveUoImOKokOJEdO4U2D9zgTlOFR_fjxJEdTPkfl4QeSKst85A8H9B9-NM-PH0-CH1-Oc8ePMP_Q5xF07EqEE7yQh09xYs9mNHWM74ErijiTo4mV4BdxjsTjETuP5D3C7mhGpvic48xS4suD1fhoPFGSI7-QU
@sampsyo
sampsyo / rn.py
Created February 21, 2014 18:52
import re
import sys
import os
for path in sys.argv[1:]:
with open(path) as f:
contents = f.read()
m = re.search(r'created_at: (.*)', contents)
d, m, y = map(int, m.group(1).split('/'))
diff --git a/beets/importer.py b/beets/importer.py
index 0fc11f6..52e06a4 100644
--- a/beets/importer.py
+++ b/beets/importer.py
@@ -254,7 +254,6 @@ class ImportSession(object):
for stage_func in plugins.import_stages():
stages.append(plugin_stage(self, stage_func))
stages += [manipulate_files(self)]
- stages += [finalize(self)]
pl = pipeline.Pipeline(stages)
### Keybase proof
I hereby claim:
* I am sampsyo on github.
* I am samps (https://keybase.io/samps) on keybase.
* I have a public key whose fingerprint is 1B73 BAD3 4D06 753B 9433 E74A 8E83 98CF 175B E458
To claim this, I am signing this object:
@sampsyo
sampsyo / pdfstill
Created May 25, 2014 17:07
embed fonts into PDFs, painlessly
#!/bin/sh
infn=$1
outfn=`basename $infn .pdf`.still.pdf
# Embed fonts.
gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outfn \
-dCompatibilityLevel=1.5 -dPDFSETTINGS=/prepress -c .setpdfwrite -f $infn
# Strip metadata crap added by Ghostscript.
exiftool -Title="" $outfn
@sampsyo
sampsyo / bug.md
Last active August 29, 2015 14:05
Clang search path bug on OS X

I ran into a problem on OS X where a Clang I compiled myself couldn't find standard C++ includes (e.g., #include <iostream>) that the system-provided Clang could find. Using -v, I found that the system Clang was searching in:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1

which actually has those files. My own Clang was saying, even when I passed it the right -resource-dir to point it at the toolchain:

ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1"

because the paths are slightly (include vs. lib). The reason seems to be that Clang had a bug that placed those include files in the wrong directory, and this was shipped in XCode 5. This bug was fixed, so now Clang looks in the "right" place, which is unfortunately wrong for the buggy system toolchain (see [Apple'

@sampsyo
sampsyo / danandbikeguy.md
Last active August 29, 2015 14:05
dan and bike guy

You said that, after passing the bike, you both came up at a red light. Like this:

back and to the left

In Fig. 1, Dan is behind Bike Guy. Then, in Fig. 2, Dan did a seemingly reasonable thing and passed Bike Guy, who was going pretty slow. However, then they both came to the red light in Fig. 3. Like any normal human, Bike Guy came up alongside or slightly in front of the car. (Unlike a normal human, he also went nuts.)

The thing is that, after the light turns green and you both go (Fig. 4), Dan just needs to pass Bike Guy again (Fig. 5). This can be kind of frustrating as a cyclist: when a car passes you, only to get into a situation where they’ll need to pass you again!

The alternate strategy is to stay behind Bike Guy: essentially to skip Fig. 2 and go straight from Fig. 1 to Fig. 3. You reduce the total number of passings from 3 to 1! And you both get where you’re going at the same speed, because the light is red anyway.

diff --git a/beetsplug/importadded.py b/beetsplug/importadded.py
index d362005..f793761 100644
--- a/beetsplug/importadded.py
+++ b/beetsplug/importadded.py
@@ -107,6 +107,11 @@ def update_album_times(lib, album):
if config['importadded']['preserve_mtimes'].get(bool):
write_item_mtime(item, mtime)
item.store()
+ if not album_mtimes:
+ # There were no mtimes recorded for these tracks. This means that the
diff --git a/test/test_logging.py b/test/test_logging.py
index a579836..1c70e00 100644
--- a/test/test_logging.py
+++ b/test/test_logging.py
@@ -72,7 +72,7 @@ class LoggingLevelTest(unittest.TestCase, helper.TestHelper):
def setUp(self):
sys.modules['beetsplug.dummy'] = self.DummyModule
beetsplug.dummy = self.DummyModule
- self.setup_beets()
+ self.setup_beets(disk=True)
@sampsyo
sampsyo / plagcheck.py
Created May 13, 2015 17:36
find the common n-grams between two documents
#!/usr/bin/env python3
import sys
def words(fn):
with open(fn) as f:
for line in f:
for word in line.split():
yield word.strip(".,?!'")