Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Williamson mattwilliamson

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am mattwilliamson on github.
  • I am aimatt (https://keybase.io/aimatt) on keybase.
  • I have a public key ASBX5bTMl9V_gtr_6q63vxAFqqj3sXOSK2LVNSHWXRUcBAo

To claim this, I am signing this object:

@mattwilliamson
mattwilliamson / sendsqs.js
Created September 6, 2017 14:40
AWS Lambda sample: Send received events to SQS as Message
View sendsqs.js
var QUEUE_URL = 'https://sqs.us-east-1.amazonaws.com/{AWS_ACCUOUNT_}/matsuoy-lambda';
var AWS = require('aws-sdk');
var sqs = new AWS.SQS({region : 'us-east-1'});
exports.handler = function(event, context) {
var params = {
MessageBody: JSON.stringify(event),
QueueUrl: QUEUE_URL
};
sqs.sendMessage(params, function(err,data){
@mattwilliamson
mattwilliamson / rtc_backup.c
Created February 3, 2017 00:51
Squeeze two floats into two uint16_t's
View rtc_backup.c
void writeRtcLatLng(void)
{
uint32_t tmp;
// RTC Backup registers have the first 2 bytes reserved. So we get to use the second half of each.
// Write lat tp first two backup registers
tmp = *(uint32_t*)⪫
rtcRegWrite(RTC_BKP_DR6, tmp >> 16);
rtcRegWrite(RTC_BKP_DR7, tmp & 0xffff);
@mattwilliamson
mattwilliamson / echoHttpRequest.js
Last active August 29, 2015 14:08 — forked from Marak/echoHttpRequest.js
Echo HTTP requests
View echoHttpRequest.js
module['exports'] = function echoHttp (hook) {
hook.debug("Debug messages are sent to the debug console");
hook.debug(hook.params);
hook.debug(hook.req.path);
hook.debug(hook.req.method);
@mattwilliamson
mattwilliamson / celery_greenlet_traceback.py
Created January 25, 2014 04:11
Celery Greenlet worker death.
View celery_greenlet_traceback.py
[2014-01-24 22:17:36,558: INFO/MainProcess] Task myservice.email.tasks.poll_email_status[cf72ef6d-effa-449e-b866-ee1c3707ce25] succeeded in 2.47090099938s: SM778890846d03dd72f29749f6a7cf517e
[2014-01-24 22:17:36,874: WARNING/MainProcess] Cannot process event on channel 'celeryev': {'pattern': None, 'type': 'message', 'channel': 'celeryev', 'data': '{"body": "eyJ1dGNvZmZzZXQiOiAwLCAidHlwZSI6ICJ0YXNrLXN0YXJ0ZWQiLCAidXVpZCI6ICIyOWVhODQx\nMC02ODk5LTQ1ZTEtYTg3NC1iM2ExOTE1MzRmODgiLCAiY2xvY2siOiA4MTU5NzYsID4+PiBlc3Rh\nbXAiOiAxMzkwNjAwNTE5LjQ5NTMzMywgImhvc3RuYW1lIjogImdyZWVubGV0c0BpbmZsaWdodDMu\nbXlob3N0Lm5ldCIsICJwaWQiOiAzOTYxfQ==", "headers": {"hostname": "greenlets@inflight3.myservice.net"}, "content-type": "application/json", "properties": {"body_encoding": "base64", "delivery_info": {"priority": 0, "routing_key": "task.started", "exchange": "celeryev"}, "delivery_mode'}
Traceback (most recent call last):
File "/www/api.myservice.com/lib/python2.6/site-packages/kombu/transport/redis.py", line 493, in _receive
@mattwilliamson
mattwilliamson / alignment.py
Created December 27, 2013 18:58
Aligning python assignments vertically.
View alignment.py
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
View webhookr_client.html
<!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
View phoneNumberFormatter.js
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;
View gist:6188354
Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken.
@mattwilliamson
mattwilliamson / smtplib_custom.py
Created May 8, 2013 21:18
Customized smtplib standard library that allows you to set source host and port on the socket.
View smtplib_custom.py
#! /usr/bin/env python
'''SMTP/ESMTP client class.
This should follow RFC 821 (SMTP), RFC 1869 (ESMTP), RFC 2554 (SMTP
Authentication) and RFC 2487 (Secure SMTP over TLS).
Notes: