Skip to content

Instantly share code, notes, and snippets.

@dgrant
dgrant / ogg2mp3.py
Created May 2, 2015 05:17
Convert .ogg files to .mp3
#!/usr/bin/env python
"""Convert ogg files to mp3"""
from optparse import OptionParser
import tempfile
import os
import subprocess
class CommandException(Exception):
"""Exception that is raised if calling an external command fails"""
def __init__(self, command):
@dgrant
dgrant / remove_pyc.py
Last active April 26, 2021 21:30
Remove all *.pyc files under the given path recursively
#!/usr/bin/env python
"""
Remove all .pyc files in the path recursively
"""
from __future__ import print_function
import argparse
import os
import shutil
@dgrant
dgrant / add_eof.py
Created April 26, 2021 21:27
Add EOF to all files
#!/usr/bin/env python3
import os
LF_BYTES = b'\n'
LF_BYTE = b'\n'[0]
def get_filetypes():
types = []
for line in open('.gitattributes').readlines():
line = line.split()
@dgrant
dgrant / gist:dcaf944813e8dc4bcea5fef761c5f4aa
Created December 18, 2020 10:21
Run `mr register` on all git folders
#!/usr/bin/env python3
import argparse
import os
import subprocess
def mr_register(root):
dirs = os.listdir(root)
for _dir in dirs:
@dgrant
dgrant / ordered_dicts_python.py
Created August 25, 2013 06:20
An ordered dict implementation in Python using a second hash map to store the order information.
#!/usr/bin/env python
import random
import operator
import time
from collections import OrderedDict
import unittest
class ordered_dict(dict):
def __init__(self):
self.order = {}
@dgrant
dgrant / .gitignore
Last active August 20, 2016 06:38
Script to encode videos from my video camera. Runs multiple ffmpeg processes to optimize CPU usage rather than relying on one ffmpeg process to use multiple processors.
__pycache__/
@dgrant
dgrant / timeit.py
Created August 20, 2016 06:35
A script that measure how long execution of something took, good for Windows where there is no "time" command
#!/usr/bin/env python
import subprocess
import sys
import time
def main():
start_time = time.time()
subprocess.call(' '.join(sys.argv[1:]), shell=True)
delta = time.time() - start_time
hours = int(round(delta / 3600, 0))
@dgrant
dgrant / canadapost.py
Last active July 14, 2016 16:04
Finds Canada Post rates to send a parcel or oversized/non-standard envelope domestically, to the US, or internationally. Particularly useful for people selling items on eBay. It will print our rates to different destinations around the country/US/world so you can get a feel for the min/average/max rate.
#!/usr/bin/env python3
import argparse
import base64
import xml.etree.ElementTree as ET
import urllib.request, urllib.error, urllib.parse
import operator
import time
from canadapostconf import username, password
@dgrant
dgrant / compare_excelleris_oscar_labs.py
Last active January 4, 2016 13:39
A utility to find what labs from Excelleris are missing from OSCAR
#!/usr/bin/env python3
"""
A utility to find what labs from Excelleris are missing from OSCAR
"""
import argparse
import csv
import datetime
from operator import itemgetter
import unittest
@dgrant
dgrant / check_vancouver_swimming_lessons.py
Last active December 18, 2015 04:39
Checks swimming lessons availability with the City of Vancouver.
#!/usr/bin/env python2
"""
Search for swimming lessons on the Vancouver Aquatic Services web page
that match certain criteria.
"""
import urllib2
import json
#WP=Lord Byng