Skip to content

Instantly share code, notes, and snippets.

Follow your passion.

Hank Wang hanksudo

Follow your passion.
Block or report user

Report or block hanksudo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
hanksudo / linebyline.js
Last active Aug 29, 2015
Read data line by line and turn in to JSON
View linebyline.js
var fs = require('fs');
var readline = require('readline');
var stream = require('stream');
var instream = fs.createReadStream('test.txt', 'utf8');
var outstream = new stream;
var rl = readline.createInterface(instream, outstream);
var obj = {}
rl.on('line', function (line) {
hanksudo /
Created Apr 11, 2014
SSH without
sudo curl "" -o /usr/bin/ssh-copy-id
sudo chmod +x /usr/bin/ssh-copy-id

ssh-copy-id -i ~/.ssh/ user@host
ssh-copy-id -i ~/.ssh/ "user@host -p 8129" 
git checkout --track origin/daves_branch
hanksudo / keybind.sublime-map
Last active Aug 29, 2015
Mako translate warp with selection
View keybind.sublime-map
{ "keys": ["alt+super+t"], "command": "insert_snippet", "args": {"name": "Packages/User/mako-translate.sublime-snippet"} }
hanksudo / Perform an operation on each dictionary
Created May 15, 2014
Perform an operation on each dictionary value
View Perform an operation on each dictionary
my_dict.update((x, y*2) for x, y in my_dict.items())
View Sort list by
from operator import itemgetter
newList = sorted(listToSort, key=itemgetter('key'))
hanksudo /
Created Jun 17, 2014
Mount NTFS USB to read / write

Step 1

$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
for n in range(2, 100):
for i in range(2, n):
if n % i == 0:
print '{} is a prime!'.format(n)
hanksudo /
Last active Aug 29, 2015
read CSV demo in Python 2.7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv
with open('sample_data.csv') as f:
for row in csv.reader(f):
print row
hanksudo /
Last active Aug 29, 2015
use setdefault to set dict default value for missing key.
# prefer
def _addErr1(errors, field, message):
errors.setdefault(field, []).append(message)
# not prefer
def _addErr2(errors, field, message):
if not field in errors:
errors[field] = []
You can’t perform that action at this time.