Skip to content

Instantly share code, notes, and snippets.

View hanksudo's full-sized avatar
:octocat:
Follow your passion.

Hank Wang hanksudo

:octocat:
Follow your passion.
View GitHub Profile
@hanksudo
hanksudo / linebyline.js
Last active August 29, 2015 13:55
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 April 11, 2014 11:52
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" 
@hanksudo
hanksudo / checkout_remote_branch.sh
Created May 8, 2014 09:46
Checkout remote branch
View checkout_remote_branch.sh
git checkout --track origin/daves_branch
@hanksudo
hanksudo / keybind.sublime-map
Last active August 29, 2015 14:01
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 07:48
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())
@hanksudo
hanksudo / Sort list by key.py
Created May 15, 2014 07:49
Sort list by key
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 June 17, 2014 14:11
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)
@hanksudo
hanksudo / ex_csv.py
Last active August 29, 2015 14:07
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 / ex_prime.py
Created October 20, 2014 06:46
Prime numbers
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 / dict_setdefault.py
Last active August 29, 2015 14:12
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)