Skip to content

Instantly share code, notes, and snippets.

View nqbao's full-sized avatar
Make Stuff Works

Bao Nguyen nqbao

Make Stuff Works
View GitHub Profile
@nqbao
nqbao / copy-snapshot.sh
Created November 8, 2017 07:15
Copy AMI across accounts
#!/bin/bash
raw=$1
ami_id=$(echo "$raw" | cut -d"," -f1)
image_name=$(echo "$raw" | cut -d"," -f2)
echo "Copying $image_name ($ami_id)"
aws ec2 modify-image-attribute --image-id $ami_id --launch-permission "{\"Add\":[{\"UserId\":\"$TO_ACCOUNT\"}]}" --profile $FROM_PROFILE
aws ec2 copy-image --name "$image_name" --source-image-id $ami_id --source-region $SOURCE_REGION --profile $TO_PROFILE
@nqbao
nqbao / gpu_allocation.py
Created August 27, 2017 17:58
gpu_allocation.py
import os
import logging
import gpustat
logger = logging.getLogger(__name__)
def get_free_gpu_indices():
stats = gpustat.GPUStatCollection.new_query()
used_gpus = set()
@nqbao
nqbao / install_fluentd.sh
Last active July 25, 2017 19:01
Quick script to install fluentd
#!/bin/bash
sudo apt-get update
sudo apt-get -y install ruby-dev libjemalloc-dev net-tools
sudo gem install fluentd -v "~> 0.14.0" --no-ri --no-rdoc
sudo gem install fluent-plugin-record-modifier
sudo gem install fluent-plugin-cloudwatch-logs
@nqbao
nqbao / bench_grpc_3.py
Last active April 25, 2017 17:13
bench_grpc_3.py
#!/usr/bin/env python
import grpc.beta.implementations
import tensorflow_serving.apis.predict_pb2 as predict_pb2
import tensorflow_serving.apis.prediction_service_pb2 as prediction_service_pb2
import random
import numpy as np
import tensorflow as tf
import threading
### Keybase proof
I hereby claim:
* I am nqbao on github.
* I am nqbao (https://keybase.io/nqbao) on keybase.
* I have a public key ASC9DdgdV1S915zhkOswS6NVKUYnAoYm4IEpFJcFJrig8Qo
To claim this, I am signing this object:
@nqbao
nqbao / bench_grpc2.py
Last active February 27, 2017 22:46
TF gRPC Benchmark
import grpc.beta.implementations
import tensorflow_serving.apis.predict_pb2 as predict_pb2
import tensorflow_serving.apis.prediction_service_pb2 as prediction_service_pb2
import numpy as np
import tensorflow as tf
import threading
from timeit import timeit
# from concurrent.futures import ProcessPoolExecutor
@nqbao
nqbao / openvpn_auth.sh
Created February 2, 2017 05:16
OpenVPN auth-user-pass-verify example script
#!/bin/bash
readarray -t lines < $1
username=${lines[0]}
password=${lines[1]}
if [[ "$password" == "bao" ]]; then
echo "ok"
@nqbao
nqbao / export.py
Created January 27, 2017 18:05
Export named signatures from a tf.contrib.learn estimator
# XXX: Only work with tf 11
from tensorflow.contrib.learn.python.learn.utils import export
from tensorflow.contrib.session_bundle import exporter
def my_input_fn():
# Return features tensors, the name is empty because when we build the model
# we feed in empty column name
return {
"": tf.placeholder(tf.float32, shape=[None, 4])
@nqbao
nqbao / read_serving.py
Created January 26, 2017 21:25
read serving signatures from tensorflow
# XXX: this only works for tf 0.11
import tensorflow as tf
from tensorflow.core.protobuf import meta_graph_pb2
from tensorflow.contrib.session_bundle import manifest_pb2
def read_serving_signatures(meta_file):
tf.reset_default_graph()
with tf.Session() as sess:
new_saver = tf.train.import_meta_graph(meta_file)
#<source>
# @type http
# port 8888
#</source>
<source>
@type tail
path /tmp/*.log
tag file.*
read_from_head true