Skip to content

Instantly share code, notes, and snippets.

@amichaelgrant
amichaelgrant / gist:44c8faa2e46055c10aaa
Created March 14, 2016 22:56
Running Lua Script in Redis from Nodejs Client
-- setnex.lua
local key = ARGV[1]
local expiry = ARGV[2]
local value = ARGV[3]
local reply = redis.call("SETNX", key, value)
if 1 == reply then
redis.call("EXPIRE", key, expiry)
end
return reply
You can call it from node_redis like this:
@amichaelgrant
amichaelgrant / s3.sh
Created February 1, 2016 16:57 — forked from chrismdp/s3.sh
Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (http://soltrader.net)
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
{
path=$1
@amichaelgrant
amichaelgrant / supervisord-example.conf
Created January 30, 2016 01:54 — forked from didip/supervisord-example.conf
Example configuration file for supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
nodaemon=false ; run supervisord as a daemon
@amichaelgrant
amichaelgrant / gist:71989b9fb7479a6beda7
Created January 29, 2016 20:57
Keepalive startup script for ubuntu
#! /bin/sh
#
# keepalived LVS cluster monitor daemon.
#
# Written by Andres Salomon <dilinger@voxel.net>
#
### BEGIN INIT INFO
# Provides: keepalived
# Required-Start: $syslog $network $remote_fs
# Required-Stop: $syslog $network $remote_fs
! Configuration file for keepalived
vrrp_script chk_nginx {
script "pidof nginx"
interval 2
weight -60
}
vrrp_instance VI_1 {
debug 2
@amichaelgrant
amichaelgrant / Git push deployment in 7 easy steps.md
Created November 1, 2015 09:01 — forked from thomasfr/Git push deployment in 7 easy steps.md
7 easy steps to automated git push deployments. With small and configurable bash only post-receive hook
@amichaelgrant
amichaelgrant / Makefile
Created October 30, 2015 19:34 — forked from dspezia/Makefile
Example of pipelining with hiredis
OBJ = genload.o
BINS = genload
CC=g++
OPTIMIZATION?=-O3
CFLAGS?=$(OPTIMIZATION) $(ARCH) $(PROF) -I ../hiredis
CCLINK?=-pthread
LDFLAGS?=-L../hiredis -lhiredis -lm
OBJ = example.o
@amichaelgrant
amichaelgrant / boost_property_tree_json_array.cpp
Created October 23, 2015 06:25 — forked from mloskot/boost_property_tree_json_array.cpp
Simple example of parsing and consuming JSON array with boost::property_tree
#ifdef _MSC_VER
#include <boost/config/compiler/visualc.hpp>
#endif
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <cassert>
#include <exception>
#include <iostream>
#include <sstream>
# Automatically instal the latest nginx
wget -O - http://nginx.org/keys/nginx_signing.key | sudo apt-key add -
#Make a backup copy of your current sources.list file
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
#Now copy the following repositories to the end of ` /etc/apt/sources.list`
echo "deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx" | sudo tee -a /etc/apt/sources.list
#!/bin/bash
BIND_NETWORK="192.168.5.0"
SHARED_VIP="192.168.5.30"
apt-get update
apt-get install -y pacemaker ntp
# Configure Corosync
echo "START=yes" > /etc/default/corosync
sed -i "s/bindnetaddr: 127.0.0.1/bindnetaddr: $BIND_NETWORK/g" /etc/corosync/corosync.conf