Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# coding: utf-8
#
# Copyright (c) 2015, Torbjörn Lönnemark <tobbez@ryara.net>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
@tobbez
tobbez / music-renamer.py
Last active August 29, 2015 14:17
Rename music files in a directory according to tags
#!/usr/bin/env python2
# coding: utf-8
#
# Copyright (c) 2015, tobbez
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
@tobbez
tobbez / gist:324792
Created March 8, 2010 02:38
Getting the target of an HTTP redirect in C#
string GetRedirectTarget(string url)
{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
return response.Headers.Get("Location");
}
@tobbez
tobbez / whatstats.loader.chrome.user.js
Created March 13, 2010 16:47
WhatStats loader for Chrome
// ==UserScript==
// @name WhatStats
// @description Provides pretty charts on your user profile page on What.cd
// @namespace tobbez
// @author tobbez
// @version 1.0
// @date 2010-03-11
// @include http*://*what.cd/*
// ==/UserScript==
@tobbez
tobbez / FileChecker.cpp
Created March 14, 2010 21:31
Word counts in files
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
class FileChecker {
private:
map<string, unsigned> keywords;
@tobbez
tobbez / quine.c
Created March 19, 2010 01:04
C program that writes out its own source
int X = 184;void w(char *s){int i=0;for(i=0;i<strlen(s);++i) if (s[i] == '"' || s[i] == '\\') { write(1,"\\",1); write(1,s+i,1); } else { write(1,s+i,1); }} int main(void){char s[] = "int X = 184;void w(char *s){int i=0;for(i=0;i<strlen(s);++i) if (s[i] == '\"' || s[i] == '\\\\') { write(1,\"\\\\\",1); write(1,s+i,1); } else { write(1,s+i,1); }} int main(void){char s[] = \"\"; write(1, s, X); w(s); puts(s+X); return 0; }"; write(1, s, X); w(s); puts(s+X); return 0; }
@tobbez
tobbez / kym_image_dl.bash
Created March 19, 2010 02:27
dump images from knowyourmeme
# one-liner to download all images for a meme from knowyourmeme
# "i dare you to try", he said. therefore i bestow upon thee:
m="polandball"; (curl -s http://knowyourmeme.com/memes/${m} | egrep -o "/memes/${m}\?content=true&amp;photo_page=[0-9]+" && echo "/memes/${m}") | sort | uniq | sed "s/amp;//" | xargs -I URLPATH curl http://knowyourmeme.comURLPATH | sort | uniq | egrep -o "/photos/[0-9]+" | sort | uniq | xargs -I URLPATH curl -s http://knowyourmeme.comURLPATH | grep 'class="original"' | egrep -o "http://cdn[0-9]+.*[0-9]+" | xargs -I URL wget URL
@tobbez
tobbez / album-list.bash
Created July 8, 2010 22:59
Create a list of albums from flac tags
#!/bin/bash
#
# Created by tobbez
#
# Issues:
# Does not handle Various Artists-albums properly
function get_artist () {
metaflac --show-tag=ARTIST "$1" | cut -d= -f2
}
// ==UserScript==
// @name Hide translation threads from the project forum
// @namespace tobbez
// @include http*://*what.cd*
// ==/UserScript==
if (document.location.pathname == '/forums.php' && document.location.search == '?action=viewforum&forumid=45') {
var rows = $('tr.rowa, tr.rowb').objects;
for (var i in rows) {
if (rows[i].getElementsByTagName('a')[0].innerHTML.match(/^Translating the rules into/)) {
@tobbez
tobbez / youtube-rip-channel.py
Created August 17, 2010 13:02
youtube-rip-channel.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2010, Torbjörn Lönnemark
import feedparser
import sys
def main():
if len(sys.argv) != 2:
print "Usage: " + sys.argv[0] + " <channel-name>"
return