Skip to content

Instantly share code, notes, and snippets.

# ISO 3166-1 Countries and country codes in a list of tuples
# Useful for Django model choice fields and dropdowns
# http://www.iso.org/iso/english_country_names_and_code_elements
countries = [
("AF","Afghanistan"),
("AL","Albania"),
("DZ","Algeria"),
("AS","American Samoa"),
("AD","Andorra"),
#!/usr/bin/env python
# Run as cronjob to have a daily fresh desktop
# background from the NASA Image of the day gallery.
# You might need to install BeautifulSoup and appscript
# easy_install BeautifulSoup appscript
from os.path import basename
from BeautifulSoup import BeautifulStoneSoup
from appscript import app, mactypes
from urllib2 import urlopen
#!/usr/bin/env node
// Use to load test Faye node.js comet server
// $ ./bayeux_load_client.js [number_of_clients]
var repl = require('repl');
var sys = require('sys');
var faye = require('./faye-node');
var room = '/chat/demo';
#!/usr/bin/env node
var http = require('http'),
faye = require('./faye-node');
var received = 0,
sent = 0;
function getTimestamp () {
return(new Date());
#user nobody;
worker_processes 1;
worker_rlimit_nofile 500000;
events {
worker_connections 500000;
}
http {
var http = require('http'),
host = 'aws01',
creation_delay = 5,
reporting_delay = 3000,
clients = [],
limit = process.argv[2] || 500,
headers = {
'Host' : host
};
@mgunneras
mgunneras / printhid.c
Created August 28, 2011 16:14
Prints a HID device to stdout
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
@mgunneras
mgunneras / pull_zmq.py
Created August 28, 2011 16:33
Publish data from file or stdin to a zmq socket
#! /usr/bin/env python
"""
Prints data from zmq PULL socket to stdout
"""
import zmq
import sys
def get_socket(host, port):
context = zmq.Context()
@mgunneras
mgunneras / thumbnailer.sh
Created January 17, 2015 22:07
Convert image files into smaller thumbnails using Imagemagick
#! /bin/bash
#
# Recursively convert image files in IN_DIR into smaller jpegs
# Copy all other files straight over
# Resulting files (including folder structure) ends up in in IN_DIR/../thumbs/
IN_DIR=$1
is_image() {
local name=$1
@mgunneras
mgunneras / gist:19b1655cde8129b278c4
Created June 24, 2015 20:42
Relay controller CLI for controlanything.com R8x
#! /usr/bin/env python
# https://s3.amazonaws.com/assets.controlanything.com/manuals/R4xR8xPro.PDF
# Example usage to turn on relay index 1 3 and 6:
# ./relay.py --on 1 3 6
import serial
import time
class Relay(serial.Serial):