Skip to content

Instantly share code, notes, and snippets.

@dgrant
dgrant / gist:dcaf944813e8dc4bcea5fef761c5f4aa
Created Dec 18, 2020
Run `mr register` on all git folders
View gist:dcaf944813e8dc4bcea5fef761c5f4aa
#!/usr/bin/env python3
import argparse
import os
import subprocess
def mr_register(root):
dirs = os.listdir(root)
for _dir in dirs:
@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";