Skip to content

Instantly share code, notes, and snippets.

View mattwilliamson's full-sized avatar

Matt Williamson mattwilliamson

View GitHub Profile
@mattwilliamson
mattwilliamson / alignment.py
Created December 27, 2013 18:58
Aligning python assignments vertically.
class MyModel(Model):
start_time = DateTimeField()
end_time = DateTimeField()
comment = TextField()
@mattwilliamson
mattwilliamson / webhookr_client.html
Created September 24, 2013 14:37
Webhookr client socket test
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
@mattwilliamson
mattwilliamson / phoneNumberFormatter.js
Created August 14, 2013 22:03
Formats phone numbers to US or E164
function formatNumber(number) {
number = number.replace(/\D+/g, '');
number = number.replace(/^(1)(\d{0,2})$/, '$1($2');
number = number.replace(/^(1)(\d{3})$/, '$1($2)');
number = number.replace(/^(1)(\d{3})(\d{1,3})$/, '$1($2) $3');
number = number.replace(/^(1)(\d{3})(\d{3})(\d{1,4})$/, '$1($2) $3-$4');
number = number.replace(/^(1)(\d{3})(\d{3})(\d{4})(\d+)$/, '$1($2) $3-$4 x$5');
number = number.replace(/^(1)(.*)/, '$1 $2');
return '+' + number;
Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken.
@mattwilliamson
mattwilliamson / config.h
Created July 27, 2012 20:52
MultiWii328 v1 config file
/*************************************************************************************************/
/**** CONFIGURABLE PARAMETERS ****/
/*************************************************************************************************/
/***************************** Motor minthrottle *******************************/
/* Set the minimum throttle command sent to the ESC (Electronic Speed Controller)
This is the minimum value that allow motors to run at a idle speed */
//#define MINTHROTTLE 1300 // for Turnigy Plush ESCs 10A
//#define MINTHROTTLE 1120 // for Super Simple ESCs 10A
//#define MINTHROTTLE 1220
#include <Wire.h>
void i2c_write(int address, byte reg, byte data) {
// Send output register address
Wire.beginTransmission(address);
Wire.write(reg);
// Connect to device and send byte
Wire.write(data); // low byte
Wire.endTransmission();
}
/*
AeroQuad v3.0.1 - February 2012
www.AeroQuad.com
Copyright (c) 2012 Ted Carancho. All rights reserved.
An Open Source Arduino based multicopter.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
@mattwilliamson
mattwilliamson / gist:2437412
Created April 21, 2012 14:38
Aeroquad Remote PC Debugging
1 joystick(s) detected.
Joystick 0: Saitek ST290 Pro
Axis: 0, value: 125
Throttle:0 Roll:125 Pitch:0 Yaw:0 A1:250
Axis: 1, value: 125
Throttle:0 Roll:125 Pitch:125 Yaw:0 A1:250
Axis: 2, value: 125
Throttle:0 Roll:125 Pitch:125 Yaw:125 A1:250
Axis: 3, value: 250
Throttle:0 Roll:125 Pitch:125 Yaw:125 A1:250
@mattwilliamson
mattwilliamson / gist:1770625
Created February 8, 2012 15:57
Snippet to add to django.db.models.base.Model to make decimal fields work with django-nonrel
# Hack by @mattwilliamson because DecimalFields are being set as unicode for some reason with the
# nonrel or maybe mongo updates
def __setattr__(self, name, value):
for field in iter(self._meta.fields):
if field.attname == name:
if field.get_internal_type() == 'DecimalField':
value = field.to_python(value)
break
super(Model, self).__setattr__(name, value)
@mattwilliamson
mattwilliamson / gist:1340368
Created November 4, 2011 20:13
Metaclass Django Model Instance Caching
import logging
import uuid
import re
from decimal import Decimal
from django.conf import settings
from django.db import models
from django.db.models import signals
from django.dispatch import receiver
from django.core.cache import cache