Skip to content

Instantly share code, notes, and snippets.

View guyc's full-sized avatar

Guy Carpenter guyc

  • Clearwater Software
  • Australia
View GitHub Profile
@guyc
guyc / gist:5088179
Created March 5, 2013 05:11
Testing UDP broadcast on unconfigured network
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <net/if.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
@guyc
guyc / gist:5472760
Created April 27, 2013 11:25
openscan source for one tentacle arc.
// arc is defined by the inner radius
small = 1;
$fa = 4;
//$fs = 1;
segmentInnerRadius = 300;
segmentArc = 10; // degrees
segmentWidth = 40;
@guyc
guyc / sketch_may01a.ino
Created May 1, 2013 04:28
The file that is currently on an Arduino Uno with a serial number of 6493234383835120E1B0
#include "LPD8806.h"
#include "SPI.h"
// Example to control LPD8806-based RGB LED Modules in a strip
/*****************************************************************************/
// Number of RGB LEDs in strand:
int nLEDs = 32;
// number that we will not be writing to
@guyc
guyc / xmlsort.py
Created March 21, 2016 01:25
This is a quick-and-dirty tool to reformat XML configuration files to make it possible to diff them. It only preserves tag and attribute values.
#!/usr/bin/python
from xml.etree import ElementTree as ET
import sys
def compareString(a,b):
aLower = a.lower()
bLower = b.lower()
order = 0
if aLower > bLower:
@guyc
guyc / tachoFilter1
Last active November 27, 2016 01:37
Filter out short spikes from tacho sensor
unsigned long hTime = 0; // integer for storing high time
unsigned long lTime = 0; // integer for storing low time
const int window = 4; // sliding window size
const int shift = 3; // reject pulses if width < sum * (window / 2^shift) or 1/2 of mean pulse
unsigned long highFilter[window];
int highIndex = 0;
unsigned long lowFilter[window];
int lowIndex = 0;
#!/usr/bin/env bash
# When sourced, this script will export the AWS_ACCESS_KEY_ID and
# AWS_SECRET_ACCESS_KEY credentials from the a specific profile in
# ~/.aws/credentials.
#
# Usage:
#
# export-aws-credentials [PROFILE]
#
@guyc
guyc / capswitch.py
Created May 12, 2013 22:37
Test code for capacitive switch on raspberry pi.
import wiringpi
import time
# 1M external pull-up resistor
# 1) set pin low and to output to discharge
# 2) make the pin an input without the internal pull-up on
# 3) read input and see how long it takes to go high
# ref: https://github.com/WiringPi/WiringPi-Python
# pins: https://projects.drogon.net/raspberry-pi/wiringpi/pins/
@guyc
guyc / find-duplicates.py
Created April 26, 2013 03:45
Script for finding duplicate image files created by picasa import.
#!/usr/bin/env python
# Picasa sometimes duplicates imports and it adds a -NNN
# suffix (older versions seemed to use -N). This code
# finds files with this naming scheme, and looks for the base
# file in the same dirctory. If it finds the base, and the
# base has the same length, same md5 hash, the duplicate
# is suggested for deletion.
# Output is a set of 'rm <filename>' commands that can
@guyc
guyc / encode_user_data.py
Created April 23, 2019 05:55
Encode a bash file into base64 cloudinit user data.
#!./env/bin/python
import base64
import sys
def encode_user_data(lines):
"""
Input is an array of lines that together make a script.
Output is a base64 encoded block suitable for the userdata parameter
of an instance config.
"""
@guyc
guyc / find_latest_ami.py
Created April 23, 2019 05:58
Find the latest available ami owned by me with a specific Name tag.
#!./env/bin/python
import boto3
import sys
def format_filter(fils=None, tags=None):
f = []
if fils is not None:
for k, v in fils.items():
f.append({'Name': k, 'Values': [v]})