Skip to content

Instantly share code, notes, and snippets.

@jamescw
jamescw / generate_id.py
Last active November 29, 2016 16:07
A simple one way hash function for generating unique IDs from a constant set of personal fields
def generate_id(
first_name,
father_name,
last_name,
mother_full_name,
gender,
birthday_day,
birthday_month,
birthday_year
@jamescw
jamescw / gist:1a15baf57528c8ab4ef9
Created March 18, 2015 08:48
Shape file export for django import export
from import_export.formats.base_formats import Format
from shapely.geometry import Point, mapping
from fiona import collection
class SHPFormat(Format):
def get_title(self):
return 'shp'
number = '07045656789'
def hash_to_digits(num, length=10):
return abs(hash(num)) % (10 ** length)
hash = hash_to_digits(number)
@jamescw
jamescw / vagrant.py
Created May 23, 2012 10:18
Create vagrant VMs using fabric
from fabric.api import *
def create_local_vm(name=None, image="lucid32"):
if not name:
name = env.project + "_VM"
local("vagrant box add {0} http://files.vagrantup.com/{1}.box".format(name,image))
local("vagrant init {0}".format(name))
@jamescw
jamescw / bootCheck.ino
Created April 20, 2012 18:17
Identify which boot loader is loaded in the ATmega328
// Detect which type of boot loader is present, using a fixed built-in table
// 2012-03-06 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
#include <avr/pgmspace.h>
#include <util/crc16.h>
#define VERSION "2"
// list of all known boot loaders with their unique signatures
struct { word crc; const char* desc; } signatures[] = {
/* JeeNode / JeeNode USB / JeeSMD
-------|-----------------------|----|-----------------------|----
| |D3 A1 [Port2] D5 | |D3 A0 [port1] D4 | |
|-------|IRQ AIO +3V GND DIO PWR| |IRQ AIO +3V GND DIO PWR| |
| D1|TXD| ---- ---- |
| A5|SCL| D12|MISO|+3v | |
| A4|SDA| Atmel Atmega 328 D13|SCK |MOSI|D11 |
| |PWR| JeeNode / JeeNode USB / JeeSMD |RST |GND | |
| |GND| D8 |BO |B1 |D9 |
| D0|RXD| ---- ---- |