Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / m4a2mp3.sh
Created May 2, 2015 05:18
Convert .m4a to .mp3
#!/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 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 / time_shift.py
Created May 2, 2015 05:16
Shift EXIF times of pictures (fixes 'CreateDate', 'DateTimeOriginal', 'ModifyDate')
#!/usr/bin/env python3
import datetime
import argparse
import math
import os
import sys
import time
import subprocess
def parse_args():
@dgrant
dgrant / remove_non_svn_dirs.py
Created May 2, 2015 05:12
Remove non .svn dirs
#!/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 05:10
Synchronize music with a USB mp3 player
#!/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 August 29, 2015 14:20
Remove all id3 tags from an mp3
#!/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 April 27, 2015 01:13
Git batch (run git commands in all sub-directories)
#!/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),