Skip to content

Instantly share code, notes, and snippets.

View Tonyliu2ca's full-sized avatar

ApplePi(苹果派) T.S.L Tonyliu2ca

View GitHub Profile
@Tonyliu2ca
Tonyliu2ca / logoutwatcher.sh
Created October 6, 2016 03:46 — forked from bruienne/logoutwatcher.sh
logout watcher
onLogout() {
# Insert whatever script you need to run at logout
exit
}
echo "INFO - Watching ${HOME}" >> /var/log/org.my.log
trap 'onLogout' SIGINT SIGHUP SIGTERM
while true; do
@Tonyliu2ca
Tonyliu2ca / archiveorg_mame.py
Created August 2, 2016 01:57 — forked from pudquick/archiveorg_mame.py
Download individual MAME ROMs from archive.org MAME reference sets via python over HTTP/S without downloading the entire set
import posixpath, urlparse, urllib2, re, ast, struct, cmd, os, os.path
import xml.etree.ElementTree as ET
def discover_roms(rom_url):
# step 1: based on the URL, download the _files.xml for the details
# I could do this a lot easier, but this is more fun
url_parts = urlparse.urlsplit(rom_url)
base_path, page_path = posixpath.split(url_parts.path)
files_path = posixpath.join(url_parts.path, page_path + '_files.xml')
new_parts = url_parts._replace(path=files_path)
@Tonyliu2ca
Tonyliu2ca / osx-for-hackers.sh
Created May 2, 2016 18:28 — forked from brandonb927/osx-for-hackers.sh
OSX for Hackers: Yosemite Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned. Also, please don't email me about this script, my poor inbox...
#!/bin/sh
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
@Tonyliu2ca
Tonyliu2ca / record_screencap.py
Created March 18, 2016 01:59 — forked from timsutton/record_screencap.py
Screen recording with Python and AVFoundation
#!/usr/bin/python
# pylint: disable-msg=e1101,e0611
import time
import AVFoundation as AVF
import Quartz
from Foundation import NSObject, NSURL
def main():
#
# Original version by Grant Parnell is offline (http://digitaldj.net/2011/07/21/trim-enabler-for-lion/)
# Update July 2014: no longer offline, see https://digitaldj.net/blog/2011/11/17/trim-enabler-for-os-x-lion-mountain-lion-mavericks/
#
# Looks for "Apple" string in HD kext, changes it to a wildcard match for anything
#
# Alternative to http://www.groths.org/trim-enabler-3-0-released/
# Method behind this madness described: http://forums.macrumors.com/showthread.php?t=1409151&page=4
# See discussion in comments here: https://www.macupdate.com/app/mac/39654/lion-tweaks
# And here: http://forums.macrumors.com/showthread.php?t=1410459
#!/usr/bin/python
import os
import subprocess
import sqlite3
desktop_picture_path = '/Library/Desktop Pictures/Wave.jpg'
database_location = os.path.expanduser(
'~/Library/Application Support/Dock/desktoppicture.db')
@Tonyliu2ca
Tonyliu2ca / dns_resolve.py
Created October 2, 2012 17:55
dns_resolve
import os
import re
import socket
import struct
def dns_resolve(host, dnsserver):
assert isinstance(host, basestring) and isinstance(dnsserver, basestring)
index = os.urandom(2)
hoststr = ''.join(chr(len(x))+x for x in host.split('.'))
data = '%s\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00%s\x00\x00\x01\x00\x01' % (index, hoststr)