Skip to content

Instantly share code, notes, and snippets.

View thpham's full-sized avatar

Thomas Kim Pham thpham

View GitHub Profile
#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#
@thpham
thpham / mongoStatsToGraphite.py
Created February 17, 2014 22:04
python script to send mongodb stats to graphite
import commands
import time
import sys
from socket import socket
import argparse
import os
import pymongo
from pymongo import Connection
import yaml
@thpham
thpham / rp.conf
Created March 3, 2014 14:58
Nginx configuration
server {
listen 80;
root /var/www/;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.php;
RPM and FPM
Install rpm-build via yum (from CentOS Updates and Base)
Install fpm via rubygems (requires json gem)
Creating an RPM from the apache-tomcat-7.0.25 directory and installing to /opt/tomcat/${Packagestuff}
fpm -s dir -t rpm -n tomcat -v 7.0.25 --prefix /opt/tomcat -C apache-tomcat-7.0.25
Creating a Puppet Module
fpm -s dir -t puppet -n tomcat -v 7.0.25 -C apache-tomcat-7.0.25
#!/bin/bash
source /etc/environment
hostname=$(cat /etc/machine-id)
machines=$(etcdctl ls /consul.io/bootstrap/machines)
#If there are 'machines' then the cluster has been initialised.
if [ -z "$machines" ]
then
flags="${flags} -bootstrap"
@thpham
thpham / migration.sh
Created March 27, 2015 12:05
Consul.io Leader discovery and election to invoque migration...
# check if leader exist (means associated session with the )
hasSession=$(curl -s http://localhost:8500/v1/kv/service/migration/leader | jq -r .[] | jq 'has("Session")')
if [ -z "$hasSession" ] || [ "$hasSession" = false ]; then
# create session
session=$(curl -s -X PUT -d '{"Name": "migration"}' http://localhost:8500/v1/session/create | jq -r .ID)
echo "session=$session"
leaderValue=$(curl -s http://localhost:8500/v1/kv/service/migration/leader | jq -r .[].Value | base64 --decode)
echo "leaderValue=$leaderValue"
if [ -z "$leaderValue" ] || [ "$leaderValue" != "JOB_DONE" ]; then
# try to put a lock
@thpham
thpham / haproxy.conf
Last active February 28, 2024 07:41
test config haproxy for gRPC loadbalancing
global
tune.ssl.default-dh-param 1024
defaults
timeout connect 10000ms
timeout client 60000ms
timeout server 60000ms
frontend fe_http
mode http
@thpham
thpham / iptableflip.sh
Created October 7, 2015 14:24 — forked from lewisd32/iptableflip.sh
Snippet of Unbounce script for restarting HAProxy with zero downtime
echo "Flipping tables! (╯°□°)╯︵ ┻━┻"
num_rules=3
real=3 # exposed to the ELB as port 443
test=4 # used to install test certs for domain verification
health=5 # used by the ELB healthcheck
blue_prefix=855
green_prefix=866
@thpham
thpham / .credentials
Created February 23, 2016 09:27 — forked from vrischmann/.credentials
Running SBT with a Nexus proxy with authentication
realm=Nexus Repository Manager
host=nexus.company.com
user=admin
password=admin123
#!/usr/bin/env python
from xivo_auth_client import Client as Auth
from xivo_confd_client import Client as Confd
auth = Auth('127.0.0.1', username='sylvain', password='sylvain', verify_certificate=False)
token_data = auth.token.new('xivo_user', expiration=10)
token = token_data['token']
uuid = token_data['xivo_user_uuid']