Skip to content

Instantly share code, notes, and snippets.

View cyanidium's full-sized avatar

Martin Rowe cyanidium

View GitHub Profile
@cyanidium
cyanidium / unifieddiff.py
Last active October 8, 2023 16:57 — forked from noporpoise/unifieddiff.py
Apply unified diff patches in pure python2/3
#!/usr/bin/env python
# coding=utf-8
# License: Public domain (CC0)
# Isaac Turner 2016/12/05
from __future__ import print_function
import difflib
import re
@cyanidium
cyanidium / spotify_gst_caps.py
Created July 6, 2015 04:11
Working Gst 1.0+ caps for libspotify/pyspotify to work. Took me a day to figure out why the old 0.10 caps weren't working, so I'm sharing to save someone else the same pain.
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
caps = Gst.Caps.from_string("audio/x-raw, rate=(int)44100, channels=(int)2, format=(string)S16LE, layout=(string)interleaved")
@cyanidium
cyanidium / sudoku_solver.m
Created October 19, 2014 18:36
Brute force sudoku solver using Matlab/Octave.
function [B, REM] = sudoku_solver(A)
%
% [B, REM] = sudoku_solver(A);
%
% Solves the sudoku given by A. Only works if there is no guessing needed.
%
% A,B are 9x9 matricies of the values, with 0 for blanks
% REM is a 9x9x9 matrix of the possible values, with 0 indicating it is not possible, 1 indicating
% it is, -1 indicating that it is set to that value
@cyanidium
cyanidium / LG_keyboard.py
Created October 19, 2014 18:05
Script to control LG TVs via their serial interface. Not all LG TVs have this port, but if it does then you can control it directly from the computer without a remote. This script can also be used directly from a XBMC/Kodi keymap file with some indicated modifications.
#!/usr/bin/python
# Put this file in /usr/local/bin/ then chmod +x
import sys
# You need to tell python where to look for serial module if running from a keymap.
#sys.path.append("/usr/lib/python2.7/")
#set by computer, change to your needs
SERIAL_DEV = "/dev/ttyUSB0"
@cyanidium
cyanidium / musicvideo_renamer.py
Created October 19, 2014 17:59
Tries to use last.fm music fingerprints to rename a music video file.
#!/usr/bin/env python
"""
Renames music video files in a given directory or listed in a given file by
fingerprinting the song and querying last.fm for the best match to that
fingerprint. If a directory and a file are given, uses the file.
"""
#Requires apt-get install liblastfm-fingerprint0
#Requires pylast from http://code.google.com/p/pylast/
@cyanidium
cyanidium / music_duplicate_finder.py
Created October 19, 2014 17:57
Checks music files for duplicates based on their "Artist - Title" combination, which should be correct if you also use music_tag_corrector.py to fix those up.
#!/usr/bin/env python
"""
Brute force music matching script. Gets the unique identifiers of each music
file in the music directory and finds duplicate. All duplicates are output in a
list at the end. Output defaults to STDOUT, but can be set as a file.
Tags are used to match files, so make sure the tags are correct (maybe try
music_tag_corrector.py first)
"""
@cyanidium
cyanidium / manual-package-tidy.sh
Created October 19, 2014 17:51
For Arch Linux. If you're trying to keep your installed package count under control this might help sort out what you need installed and what was installed by something else.
#!/bin/sh
#
# This script will change any explicity/manually installed packages that are
# dependended on by other packages into packages installed as dependencies. The
# idea is to minimise the manually installed packages throughout upgrades.
#
PACMAN=yaourt
TEMPDIR=$(mktemp -d /tmp/packages.XXXXXXXXXX)
@cyanidium
cyanidium / file_duplicate_finder.py
Created October 19, 2014 17:46
Old script that could do with some updates (like a safer tmp file), but sufficiently matches files and tells you about duplicates.
#!/usr/bin/env python
"""
Finds duplicate files based on MD5 hashsum
"""
import os
import os.path
import sys
import sqlite3
@cyanidium
cyanidium / music_tag_corrector.py
Created October 19, 2014 17:44
Uses fingerprinting from last.fm to identify a music file and provide tags regardless of file name or current tags.
#!/usr/bin/env python
"""
Corrects the tags of all music files in a given directory or listed in a given
file by fingerprinting the song and querying last.fm for the best match to that
fingerprint. If a directory and a file are given, uses the file. Doesn't correct
any tags to do with albums.
"""
#Requires apt-get install python-mutagen liblastfm-fingerprint1