Skip to content

Instantly share code, notes, and snippets.

@dnicolson
dnicolson / web-video.py
Created April 29, 2014 03:57
HTML5 Video Batch
"""
Dependencies:
brew remove ffmpeg
brew install --with-libvpx --with-theora --with-libvorbis ffmpeg
Usage:
python web-video.py /path/to/videos
@dnicolson
dnicolson / pre-push
Created July 3, 2014 07:09
Git pre-push hook to dump and push a MySQL database
#!/bin/bash
exit_if_pushing_database() {
if [ -f .git_push_lock ]; then
exit 0
fi
}
dump_and_push_database() {
mysqldump --skip-comments --skip-dump-date -h localhost -u root db_name > db.sql
@dnicolson
dnicolson / google-chrome-canary-default.py
Last active August 29, 2015 14:21
Google Chrome Canary Default
# Safari no longer allows choosing default browsers from a list
from LaunchServices import LSSetDefaultHandlerForURLScheme
from LaunchServices import LSSetDefaultRoleHandlerForContentType
LSSetDefaultRoleHandlerForContentType("public.html", 0x00000002, "com.google.chrome.canary")
LSSetDefaultRoleHandlerForContentType("public.xhtml", 0x00000002, "com.google.chrome.canary")
LSSetDefaultRoleHandlerForContentType("public.url", 0x00000002, "com.google.chrome.canary")
LSSetDefaultHandlerForURLScheme("http", "com.google.chrome.canary")
LSSetDefaultHandlerForURLScheme("https", "com.google.chrome.canary")
@dnicolson
dnicolson / gist:56451a826c25d9f4f6f9
Created June 5, 2015 20:33
UserScript to highlight JavaScript/Ruby articles on Hacker News
// ==UserScript==
// @name Hacker News Article Highlighter
// @version 0.1
// @author You
// @include https://news.ycombinator.com/*
// @grant none
// @noframes
// ==/UserScript==
// Requires Hacker News Enhancement Suite
#!/bin/bash
FILES=`find . -type f`
for F in $FILES
do
OUTPUT=`uniq -d $F 2> /dev/null`
LEN=${#OUTPUT}
if [ $LEN -ge 3 ]; then
echo $F
echo $OUTPUT
@dnicolson
dnicolson / pre-push
Created September 25, 2015 11:07
Git pre-push hook for printing a warning message
#!/bin/bash
printf "You are about to push, have you run ...? [y]\n"
read -s -n1 KEY < /dev/tty
if [ $KEY = 'y' ]; then
exit 0
fi
@dnicolson
dnicolson / qt-extract.py
Created November 1, 2015 21:25
Extract mdat atoms from QuickTime files
from hachoir_core.cmd_line import unicodeFilename
from hachoir_parser import createParser
import sys
def find_atoms(filename):
parser = createParser(unicodeFilename(filename))
atoms = []
for field in parser:
print '%s: %s %s + %s' % (field.description, field.name, field.absolute_address, field.size)
if 'mdat' in field.description:
@dnicolson
dnicolson / screen.py
Created November 1, 2015 21:31
Capture Mac OS X screenshot and serve over HTTP
import SimpleHTTPServer, SocketServer
import subprocess, sys, os
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
subprocess.call('screencapture -x -t jpg /tmp/screen.jpg', shell=True)
self.send_response(200)
self.send_header('Content-type', 'image/jpeg')
imgfile = open('/tmp/screen.jpg', 'rb').read()
self.send_header('Content-length', sys.getsizeof(imgfile))
@dnicolson
dnicolson / mkdir.asm
Created November 27, 2015 11:14
An example of making a syscall in assembly on OS X
; nasm -f macho64 mkdir.asm && ld -o mkdir mkdir.o && ./mkdir
%define SYSCALL_MKDIR 0x2000088
%define SYSCALL_EXIT 0x2000001
global start
section .text
start:
call mkdir
@dnicolson
dnicolson / Remove the First 3 Characters from Name.scpt
Last active December 25, 2015 21:12
JavaScript OSA to remove track numbers in song names
var PREFIX_LENGTH = 3;
var itunes = Application('iTunes'),
selection = itunes.selection();
for (var i=0; i<selection.length; i++) {
var song = selection[i],
trackNumber = parseInt(song.name().slice(0, PREFIX_LENGTH), 10),
name = song.name().slice(PREFIX_LENGTH);
if (!isNaN(trackNumber)) {