Skip to content

Instantly share code, notes, and snippets.

View dkavanagh's full-sized avatar

David Kavanagh dkavanagh

View GitHub Profile
@dkavanagh
dkavanagh / http redirect example
Last active December 18, 2015 09:18
http redirector that works with tornado. start_redirector (in my code) gets called in a background thread.. ignore the callback arg, which is None, but kwargs is passed in containing use_ssl and port as values for the redirect handler.
def start_redirector(kwargs, callback):
# can't use tornado for this (not threadsafe). Must use something else, something simpler!
http_port = 8888
if eucaconsole.config.has_option('server', 'http.port'):
http_port = eucaconsole.config.getint('server', 'http.port')
server = BaseHTTPServer.HTTPServer(('localhost', http_port),
lambda *args: RedirectHandler(kwargs, *args))
server.serve_forever()
class RedirectHandler(BaseHTTPRequestHandler):
@dkavanagh
dkavanagh / pullupdates.sh
Created June 12, 2013 18:05
pullupdates.sh
branch=`git rev-parse --abbrev-ref HEAD`
echo "pulling from "$branch
git submodule foreach git pull origin $branch
git pull origin $branch
@dkavanagh
dkavanagh / gen_metric_data.sh
Created January 11, 2016 20:13
Generate some custom metric data for testing
#!/bin/bash
while true
do
euwatch-put-data --metric-name RequestCount --namespace dak --dimensions "User=dak" --timestamp `date +%Y-%m-%dT%H:%M:%SZ` -v `expr $RANDOM / 2500`
sleep 5
done
@dkavanagh
dkavanagh / eucaconsole-template.cfn
Last active April 27, 2016 13:37
Cloud Formation template for deploying the Eucalyptus Management Console on Eucalyptus
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Deploy Eucalyptus Management Console with ELB, Autoscaling.",
"Parameters" : {
"ImageId" : {
"Description" : "The ID of the image to use for the console",
"Type" : "String",
"ConstraintDescription" : "Must be the ID of a CentOS image on the cloud."
@dkavanagh
dkavanagh / create_users.sh
Last active June 7, 2016 12:46
This script creates test users that are the same as created by eucalyptus ui tests. So, if you're setting up a test cloud by some other means (like kickstarting a package-built cloud), you can run this after getting the admin credentials.
echo "{ \"Statement\": [ { \"Effect\": \"Allow\", \"Action\": \"*\", \"Resource\": \"*\" } ] }" >all.policy
k=0
ADMIN=`cat .euca/euca-admin.ini |grep "^user" |awk '{ print $3; }'`
HOST=`cat .euca/euca-admin.ini |grep "^default-region" |awk '{ print $3; }'`
REGION=$ADMIN@$HOST
for i in ui-test-acct-00 ui-test-acct-01 ui-test-acct-02 ui-test-acct-03
do
echo "creating users for "$i
euare-accountcreate --region $REGION -a $i
euare-useraddloginprofile --region $REGION --as-account $i -u admin -p mypassword$k
@dkavanagh
dkavanagh / dual-pwm.ino
Created June 10, 2016 13:48
Dual Pwm controller w/ display
/*
This sketch illustrates how to use an arduino to provide 2 PWM signals for motor
controllers. The LCD display shows the values as driven by pot inputs. It also has
the ability to lock the two outputs to the left input pot.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
@dkavanagh
dkavanagh / pushtoremote.sh
Last active July 15, 2016 15:28
pushtoremote.sh - I revised this to work with the current branch because I never ended up passing in anything other than that.
branch=`git rev-parse --abbrev-ref HEAD`
if [ "$branch" = "master" ] || [ "$branch" = "maint-4.1" ]
then
echo "Pushing to "$branch" is no bueno."
exit -1
fi
echo "pushing to "$branch
git submodule foreach git push origin $branch
git push origin $branch
@dkavanagh
dkavanagh / deploy-console.sh
Last active July 20, 2016 18:46
This script generates a self-signed SSL cert and creates a Eucalyptus Management Console deployment using it (with ELB and AS services). It pulls in a CloudFormations template as well https://gist.github.com/dkavanagh/8cc932f0688b909547fe
#!/bin/bash
# params passed to cloud formation template
CLOUD_IP=10.111.5.150
SSH_KEY=dak-ssh-key
IMAGE_ID=emi-bc44e9e6
# create a self-signed ssl cert and install it via IAM
C=US
ST=CA
L="Santa Barbara"
@dkavanagh
dkavanagh / LifeInColor.pde
Created December 9, 2012 04:12
Conway's Game Of Life running on an Arduino, displaying on a string of RGB LEDs arranged in a matrix
/*
* Conway's "Life"
*
* Adapted from the Life example
* on the Processing.org site
*
* Written by David Kavanagh (dkavanagh@gmail.com).
*/
#include "SPI.h"
#include "Adafruit_WS2801.h"
@dkavanagh
dkavanagh / decodetest.java
Created September 13, 2016 17:57
performance testing guava and apache commons-codec base64 decoding.
import com.google.common.io.BaseEncoding;
import org.apache.commons.codec.binary.Base64;
public class decodetest {
public static void main(String [] args) {
String encoded = "eyJub25jZSI6bnVsbCwiYXRfaGFzaCI6InNSS0t4akRna2pPd3p1d25BUDBjbEx0NlRsaTh0T3VJb1c2T3lZWTJfZTAiLCJhdWQiOiI2NTkwNjdlYy05Njk4LTQ0YTgtODhlYS1kYjMxZTA3MTQ0N2EiLCJzdWIiOiI2ZjNhMTdkNC01MzhlLTQ0MzEtODg5Yi1mNjFhZWExNWNmMGMiLCJleHAiOjE0NzMzNjk1NzAsImlzcyI6Imh0dHBzOi8vYXV0aC5nbG9idXMub3JnIiwiaWF0IjoxNDczMTk2NzcwLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJka2F2YW5hZ2hAZ21haWwuY29tIiwiZW1haWwiOiJka2F2YW5hZ2hAZ21haWwuY29tIiwibmFtZSI6IkRhdmlkIEthdmFuYWdoIn0";
//String encoded = "xGB5hkL_VueWstXijYZ8FgtKPD9ZwvlYCcqLswY3qf4-Dm5ZLz67MS9uUhzwHzMwVi_1J-d5BzZvZhbqP_6AboRX4RM4gkTrkjZJMLFVbqsDdU6FnljevlDCpcca_y2XvnZYV9xa_-ugbnaT6CL6opsBfOhXCWJqkKU2Ajw6I087FHIq4XGl7yP2LUEalZqnLpIOD4vJ-Mm9MSHJmtRxKqmF-keDZulc17hY5jeOTdPVWdVWxQY1c-TqZstkIVFS9Xl4rX--A73nV1VWEILTqNXBpoUMC2c8KgmoCfsdk0KBER7hCztmtkY3o633LDZR-aHUxpSvXQjMgua2aAXnOQ==";
long start = Syste