Skip to content

Instantly share code, notes, and snippets.

View sampsyo's full-sized avatar

Adrian Sampson sampsyo

View GitHub Profile
../mutagen/tests/data/silence-3.wma
/home/asampson/mutagen/tests/data/silence-3.wma
Traceback (most recent call last):
File "dtest.py", line 10, in <module>
with audioread.gstdec.GstAudioFile(path) as f:
File "/home/asampson/audioread/audioread/gstdec.py", line 257, in __init__
raise self.read_exc
audioread.gstdec.UnknownTypeError: can't decode stream: audio/x-wma, wmaversion=(int)4, bitrate=(int)58072, depth=(int)16, rate=(int)44100, channels=(int)2, block_align=(int)13375, codec_data=(buffer)100003000000000000000000000021010000
../mutagen/tests/data/silence-3.wma
(gst-plugin-scanner:7107): GStreamer-WARNING **: Failed to load plugin '/usr/lib/gstreamer-1.0/libgstkate.so': libkate.so.1: cannot open shared object file: No such file or directory
(gst-plugin-scanner:7107): GStreamer-WARNING **: Failed to load plugin '/usr/lib/gstreamer-1.0/libgstopencv.so': libopencv_calib3d.so.2.4: cannot open shared object file: No such file or directory
(gst-plugin-scanner:7107): GStreamer-WARNING **: Failed to load plugin '/usr/lib/gstreamer-1.0/libgstopenal.so': libopenal.so.1: cannot open shared object file: No such file or directory
(gst-plugin-scanner:7107): GStreamer-WARNING **: Failed to load plugin '/usr/lib/gstreamer-1.0/libgstopenexr.so': libIlmImf-2_2.so.22: cannot open shared object file: No such file or directory
../mutagen/tests/data/silence-3.wma
** Message: pygobject_register_sinkfunc is deprecated (GstObject)
/home/asampson/mutagen/tests/data/silence-3.wma
Traceback (most recent call last):
File "dtest.py", line 10, in <module>
with audioread.gstdec.GstAudioFile(path) as f:
File "/home/asampson/audioread/audioread/gstdec.py", line 241, in __init__
raise self.read_exc
audioread.gstdec.UnknownTypeError: can't decode stream: audio/x-wma, wmaversion=(int)4, bitrate=(int)58072, depth=(int)16, rate=(int)44100, channels=(int)2, block_align=(int)13375, codec_data=(buffer)100003000000000000000000000021010000
@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(".,?!'")
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)
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
@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.

@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 / 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
### 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: