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 / 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)
#!/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')
#
# 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
@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():
@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 / 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 / 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 / mount_shares_better.py
Last active October 12, 2016 04:07 — forked from pudquick/mount_shares_better.py
Mounting shares in OS X using python and pyobjc - works with OS X 10.8+
import objc, CoreFoundation, Foundation
class attrdict(dict):
__getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__
NetFS = attrdict()
# Can cheat and provide 'None' for the identifier, it'll just use frameworkPath instead
# scan_classes=False means only add the contents of this Framework
NetFS_bundle = objc.initFrameworkWrapper('NetFS', frameworkIdentifier=None, frameworkPath=objc.pathForFramework('NetFS.framework'), globals=NetFS, scan_classes=False)
@Tonyliu2ca
Tonyliu2ca / rsync_backup.sh
Created July 26, 2017 05:54 — forked from tvwerkhoven/rsync_backup.sh
Improved script: - Check if run as root - Clarify rsync(1) flags - Add --inplace for performance, extra preservation flags - Check bless(8) target before setting Improved exclusion file: - Included files listed by Carbon Copy Cloner
#!/bin/bash
#
# This script backups an OS X system to an external volume, effectively
# cloning it. It is based on [0], [1] and [2] for OS X and [3] and [4] for
# Linux. One could also use commercial tools like SuperDuper! or Carbon Copy
# Cloner. The latter website has an interesting list[5] on what files to
# exclude when cloning.
#
# Exclusions (from CCC[5]), see rsync_excludes_osx.txt
#
@Tonyliu2ca
Tonyliu2ca / README.md
Created October 10, 2017 05:00 — forked from oznu/README.md
How to Bootcamp / Dual Boot Windows 10 on a mid-2011 iMac using USB

How to Install / Bootcamp Windows 10 on a mid-2011 iMac using USB

Apple has released support for bootcamping Windows 10, but only on 2012 Macs and later. Despite not being supported. it is possible to install Windows 10 on earlier iMacs and it seems to run quite well.

IMPORTANT: Unplug all external and physical hard drives (where possible) that you won't be installing to to avoid accidentally erasing them. Also make note of which drives and partitions remain (e.g. System and Storage hard drives), and be super careful to not erase the wrong one.

RECOVERY: If you nuke your machine, restore your time machine backup. Instructions here.

Requirements