Skip to content

Instantly share code, notes, and snippets.

View hisplan's full-sized avatar
🎯
Focusing

Jaeyoung Chun hisplan

🎯
Focusing
  • Memorial Sloan Kettering Cancer Center
  • New York, NY
  • 23:22 (UTC -04:00)
View GitHub Profile
@hisplan
hisplan / argparse-example.py
Created November 5, 2015 18:46
Python argparse mutually exclusive group
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--foo', action='store_true')
group.add_argument('--bar', action='store_false')
settings = parser.parse_args()
@hisplan
hisplan / size-human-format.py
Created December 22, 2015 05:13
size in human format (K,M,G,T,P)
def human_format(num):
magnitude = 0
while abs(num) >= 1000:
magnitude += 1
num /= 1000.0
# add more suffixes if you need them
return '%.2f%s' % (num, ['', 'K', 'M', 'G', 'T', 'P'][magnitude])
print('the answer is %s' % human_format(7436313)) # prints 'the answer is 7.44M'
@hisplan
hisplan / kafka-producer.py
Last active December 22, 2015 13:25
Python Kafka Producer
from kafka import SimpleProducer, KafkaClient
kafka = KafkaClient('localhost:9092')
producer = SimpleProducer(kafka)
producer.send_messages(b'my-topic', b'some message')
producer.send_messages(b'my-topic', b'this method', b'is variadic')
producer.send_messages(b'my-topic', u'안녕?'.encode('utf-8'))
@hisplan
hisplan / sh
Created January 26, 2016 15:07
nohup for node.js server
nohup node server.js > server.log 2>&1&
echo $! > server_pid.txt
@hisplan
hisplan / silent-output.sh
Last active August 6, 2016 00:55
bash silent output
#!/bin/bash
scriptname &>/dev/null
@hisplan
hisplan / get-docker-size-in-mib.sh
Created March 1, 2017 03:30
Get Docker Size in MiB
#!/bin/bash
function convert_to_mib {
local mib=$1
if [ $2 = "KB" ]
then
# if less than 1 MiB, just return 1 MiB
mib=1
fi
@hisplan
hisplan / parse.sh
Created March 2, 2017 16:33
parse docker label
sudo docker inspect bwa | python -c "import json; import sys; j=json.loads(sys.stdin.read()); print j[0]['Config']['Labels']"
@hisplan
hisplan / rsync-remote-host.sh
Created March 2, 2017 18:40
Rsync with a non-standard ssh port
rsync -avz -e "ssh -p $portNumber" user@remoteip:/path/to/files/ /local/path/
@hisplan
hisplan / tree.py
Created March 3, 2017 05:38
When tree is not avail
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# tree.py
#
# Written by Doug Dahms
#
# Prints the tree structure for the path specified on the command line
from os import listdir, sep
npm config set init-author-name="Jaeyoung Chun"
npm config set init-author-email="jaeyoung.chun@gmail.com"