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
  • 18:13 (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 / 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 / kafka-consumer.py
Created November 5, 2015 21:17
Python Kafka Consumer
from kafka import KafkaConsumer
# To consume messages
consumer = KafkaConsumer('my-topic',
group_id='my_group',
bootstrap_servers=['localhost:9092'])
for message in consumer:
# message value is raw byte string -- decode if necessary!
# e.g., for unicode: `message.value.decode('utf-8')`
@hisplan
hisplan / install-oracle-jdk8.sh
Created December 13, 2015 05:46
Install Oracle JDK 8 on Ubuntu without prompt
sudo apt-get update
sudo apt-get install -y python-software-properties debconf-utils
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | sudo debconf-set-selections
sudo apt-get install -y oracle-java8-installer
@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 / 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 / read-from-stdin.sh
Last active March 3, 2017 16:07
Python: read from stdin
echo "hello" | python -c "import sys; sys.stdout.write( sys.stdin.read() )"
@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']"