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 / clean.py
Last active April 24, 2023 05:34
my snippets
# remove outliner
upper = df.quantile(0.99)
cols = set(list(df)) - {"ts", "tss"}
df_clean = df
for col in cols:
df_clean = df_clean[(df_clean[col] < upper[col])]
streamlit
openai <= 1
@nqbao
nqbao / lambda_s3_event.py
Created February 13, 2020 21:36
Snippet to handle s3 events
import boto3
import json
import urllib.parse
import uuid
import os
def lambda_handler(event, context):
sfn = boto3.client('stepfunctions')
@nqbao
nqbao / lambda_slack.py
Created February 6, 2020 21:46
Snippet for integration slack with lambda
import json
import os
import urllib3
bot_token = os.environ.get('SLACK_BOT_TOKEN')
def send_slack_message(channel, message, blocks=[], attachments=[]):
http = urllib3.PoolManager()
#!/usr/bin/env python
# grab the first unformatted disk and format it, then label it and update to fstab
# this must be ran as root
import subprocess
import time
import os
import datetime
import sys
import sys
import redis
from concurrent.futures import ThreadPoolExecutor
from tqdm import tqdm
source = redis.Redis.from_url(sys.argv[1])
dest = redis.Redis.from_url(sys.argv[2])
print "Migrating %s -> %s" % (source, dest)
@nqbao
nqbao / ssm_parameter_store.py
Last active March 21, 2024 00:15
Python class to provide a dictionary-like interface to access AWS SSM Parameter Store easily
# Copyright (c) 2018 Bao Nguyen <b@nqbao.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@nqbao
nqbao / install.sh
Last active February 15, 2018 07:21
Install common prometheus exporter to a node
#!/bin/bash
if [ ! -f "/etc/systemd/system/node_exporter.service" ]; then
wget https://github.com/prometheus/node_exporter/releases/download/v0.15.2/node_exporter-0.15.2.linux-amd64.tar.gz
tar -xvf node_exporter*
sudo mv node_exporter-0.15.2.linux-amd64/node_exporter /usr/sbin
sudo bash -c 'cat <<EOT > /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
----------------------------------------
Exception happened during processing of request from ('10.26.0.173', 63486)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 290, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 318, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 652, in __init__
@nqbao
nqbao / delete_ami.py
Created December 28, 2017 19:27
A small python script to wipe out all AMI. Be extremely careful when you run this.
import boto3
ec2 = boto3.client('ec2')
images = ec2.describe_images(Owners=['self'])
for image in images['Images']:
if image['State'] == 'available':
snapshots = image['BlockDeviceMappings']