Skip to content

Instantly share code, notes, and snippets.

:octocat:
Follow your passion.

Hank Wang hanksudo

:octocat:
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
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
hanksudo / SSHwithoutPassword.md
Created Apr 11, 2014
SSH without Password.md
View SSHwithoutPassword.md
sudo curl "http://phildawson.co.uk/ssh-copy-id" -o /usr/bin/ssh-copy-id
sudo chmod +x /usr/bin/ssh-copy-id

ssh-copy-id -i ~/.ssh/id_rsa.pub user@host
ssh-copy-id -i ~/.ssh/id_rsa.pub "user@host -p 8129" 
View checkout_remote_branch.sh
git checkout --track origin/daves_branch
@hanksudo
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
hanksudo / Perform an operation on each dictionary value.py
Created May 15, 2014
Perform an operation on each dictionary value
View Perform an operation on each dictionary value.py
my_dict.update((x, y*2) for x, y in my_dict.items())
View Sort list by key.py
from operator import itemgetter
newList = sorted(listToSort, key=itemgetter('key'))
@hanksudo
hanksudo / mount_ntfs_usb_to_read_write.md
Created Jun 17, 2014
Mount NTFS USB to read / write
View mount_ntfs_usb_to_read_write.md

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)
View ex_prime.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
for n in range(2, 100):
for i in range(2, n):
if n % i == 0:
break
else:
print '{} is a prime!'.format(n)
@hanksudo
hanksudo / ex_csv.py
Last active Aug 29, 2015
read CSV demo in Python 2.7
View ex_csv.py
#!/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
hanksudo / dict_setdefault.py
Last active Aug 29, 2015
use setdefault to set dict default value for missing key.
View dict_setdefault.py
# 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] = []
errors[field].append(message)
You can’t perform that action at this time.