Skip to content

Instantly share code, notes, and snippets.

David Grant dgrant

Block or report user

Report or block dgrant

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dgrant
dgrant / timeit.py
Created Aug 20, 2016
A script that measure how long execution of something took, good for Windows where there is no "time" command
View timeit.py
#!/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 / m4a2mp3.sh
Created May 2, 2015
Convert .m4a to .mp3
View m4a2mp3.sh
#!/bin/bash
#
# Dump m4a to wav (first step in conversion)
mkdir -p output
for i in *.mp3
do
mplayer -ao pcm:file="output/${i%.mp3}.wav" "$i"
done
@dgrant
dgrant / ogg2mp3.py
Created May 2, 2015
Convert .ogg files to .mp3
View ogg2mp3.py
#!/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 / time_shift.py
Created May 2, 2015
Shift EXIF times of pictures (fixes 'CreateDate', 'DateTimeOriginal', 'ModifyDate')
View time_shift.py
#!/usr/bin/env python3
import datetime
import argparse
import math
import os
import sys
import time
import subprocess
def parse_args():
View remove_non_svn_dirs.py
#!/usr/bin/env python
"""Remove all directories except .svn directories"""
import os
def remove_non_dot_svn_dirs(root):
"""Remove all directories except .svn directories under too"""
for dirpath, _, files in os.walk(root):
if dirpath.find('.svn') == -1:
for afile in files:
fullpath = os.path.join(dirpath, afile)
@dgrant
dgrant / sync_music.py
Created May 2, 2015
Synchronize music with a USB mp3 player
View sync_music.py
#!/usr/bin/env python
"""
Synchronize music with a portable device
"""
import os
import subprocess
from easygui import msgbox, choicebox, codebox, ynbox, diropenbox
def sync_music():
@dgrant
dgrant / id3_remove_all_tags.py
Last active Aug 29, 2015
Remove all id3 tags from an mp3
View id3_remove_all_tags.py
#!/usr/bin/env python
"""Remove all id3 tags"""
import sys
import eyeD3
def main():
"""main method"""
tag = eyeD3.Tag()
for afile in sys.argv[1:]:
tag.link(afile, eyeD3.ID3_V1)
@dgrant
dgrant / gb
Created Apr 27, 2015
Git batch (run git commands in all sub-directories)
View gb
#!/usr/bin/env python3
import os
import sys
import subprocess
commandMap = {
# Key(command) => Value(Tuple(list of commands to run, whether to ask for confirmation))
'rebase': (['git', 'svn', 'rebase'], False),
'diff': (['git', 'diff'], False),
'dcommit': (['git', 'svn', 'dcommit'], False),
@dgrant
dgrant / encrpytPass.pl
Created Apr 27, 2015
Generate a difficult password
View encrpytPass.pl
#!/usr/bin/perl
srand (time());
my $randletter = "(int (rand (26)) + (int (rand (1) + .5) % 2 ? 65 : 97))";
my $salt = sprintf ("%c%c", eval $randletter, eval $randletter);
my $plaintext = shift;
my $crypttext = crypt ($plaintext, $salt);
print "${crypttext}\n";
@dgrant
dgrant / convertAllps2eps.sh
Created Apr 27, 2015
Script to convert *.ps files to *.pdf and *.eps files for inclusion in Latex documents
View convertAllps2eps.sh
#!/bin/sh
#Script to convert *.ps files to *.pdf and *.eps files for inclusion in Latex documents
ONE=1
FOUND=0
numberEPS=0
numberPDF=0
for file #Traverse all files in directory.
do
You can’t perform that action at this time.