Skip to content

Instantly share code, notes, and snippets.

View johnnyg's full-sized avatar

John Garland johnnyg

  • Sydney, Australia
View GitHub Profile
@johnnyg
johnnyg / Pipfile
Last active July 10, 2022 01:44
Script to skip/mute Spotify ads
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
pydbus = "*"
pulsectl = "*"
@johnnyg
johnnyg / randomBackground
Created January 22, 2014 01:01
Randomly change desktop background
#!/bin/bash
# Changes desktop background to a pseudo-random background
# Set defaults
BG_DIR="$HOME/.backgrounds"
BG_LIST=(`cd $BG_DIR && ls *.{jp{e,}g,png,gif} 2> /dev/null`)
CURRENT_BG="`gsettings get org.gnome.desktop.background picture-uri | tail -c +8`"
NEW_BG=$CURRENT
BG_SET=0
SAME_BG=0
@johnnyg
johnnyg / grader.py
Created June 27, 2012 23:40
Calculates (interpolated) average grade
#!/usr/bin/env python2
from itertools import izip, count
from math import fsum, ceil, floor
import fileinput
GRADES = ("FL", "PC", "PS", "CR", "DN", "HD")
MARKS = dict(izip(GRADES, count()))
def average(seq):
@johnnyg
johnnyg / check_email.py
Last active July 30, 2018 01:19
Checks whether or not an email actually exists
#!/usr/bin/env python
# Requires dnspython
from __future__ import print_function
from dns.exception import DNSException
from dns.resolver import query
from smtplib import SMTP, SMTPException
def get_mx_records(domain):
try:
@johnnyg
johnnyg / gnome-shell-extension-upgrade.py
Created April 25, 2012 21:45
Allows you to manually upgrade the metadata files of gnome-shell extensions
#!/usr/bin/env python2
# Example usage: find ~/.local/share/gnome-shell/extensions/ -name 'metadata.json' -print0 | xargs -0 gnome-shell-extension-upgrade 3.4
import json
import sys
new_version = unicode(sys.argv[1])
for filename in sys.argv[2:]:
metadata = json.load(open(filename, "rb"))
@johnnyg
johnnyg / transplant.py
Created January 19, 2012 12:53
Deluge transplant script - allows you to selectively import & export torrents
from deluge._libtorrent import lt
from deluge.core.torrentmanager import TorrentManagerState
from shutil import copy, _samefile
import cPickle
import os
class Transplant(object):
def __init__(self, config_dir="", torrent_ids=None, torrents=None):
self.state_dir = ""
self.torrents = {}
@johnnyg
johnnyg / inhibit
Last active July 6, 2021 19:03
Script to easily create (and destroy) inhibitors for gnome power events
#!/usr/bin/env python2
# Creates a new inhibitor
# While this is running the specified events will be inhibited
from optparse import OptionParser
import signal
import dbus
import sys
import os
@johnnyg
johnnyg / create-thumbnails
Created September 22, 2011 13:28 — forked from damoxc/create-thumbnails
Generate thumbnails and output media info
#!/bin/bash
parse_time() {
IFS=' ' read -ra PART <<< "$1"
seconds=0
for i in "${PART[@]}"; do
number=$(expr match $i '\([0-9]\+\)')
unit=$(expr match $i '[0-9]*\([a-z]\+\)')
case $unit in
h)