Skip to content

Instantly share code, notes, and snippets.

@wware
wware / arduino_print_double.ino
Created July 25, 2015 23:59
An Arduino function to print a double-precision floating point number via Serial. Not exhaustively tested, use at your own risk.
void print_double(double val)
{
char buf[10];
int neg = (val < 0);
int exponent = 0;
if (val == 0.0) {
Serial.print("0.0");
return;
}
if (neg)
@wware
wware / wwlogger.py
Last active December 4, 2015 23:38
Install this in /usr/local/lib/python2.7/site-packages or wherever. It's useful.
import logging
import pprint
import traceback
_sql = False
try:
import sqlalchemy
import sqlparse
_sql = True
except ImportError:
@wware
wware / wwcrypt.py
Last active February 19, 2016 15:51
#!/usr/bin/env python
from Crypto.Cipher import AES
from Crypto import Random
from struct import pack
import argparse
import base64
import getpass
import math
import random

An example of Python logging over a network, starting with an example from https://docs.python.org/2/howto/logging-cookbook.html.

This is very handy if you have a rack of servers and you want to aggregate logging statements from one or several of them to in some convenient place. This is especially handy if you're using an inversion-of-control framework (my own work these days is with Buildbot, which relies upon Twisted), because a lot of what's happening may be obscured, for instance by Deferreds but also possibly by

Output from this thing currently looks like this, but I'm interested in the possibility of throwing log records in an SQL database for purposes of sorting/filtering/searching, and presenting them with something like http://datatables.net.

import time
import multiprocessing
POOLSIZE = 4
N = 10
mgr = multiprocessing.Manager()
done = mgr.dict() # they don't implement sets. Thread-safe counter???
# this MUST be a globally defined funcion
def f(x):
#!/usr/bin/env python
import logging
from Queue import Empty
from multiprocessing import Queue, Pool, Process
logging.getLogger('').setLevel(logging.DEBUG)
"""
We can send instances thru Queues, and because the Queue is not a list,
@wware
wware / rdb_fun.py
Last active November 20, 2019 19:57
"""
Provide access to a Bash shell on the remote machine during a RemotePdb session.
"""
import os
import remote_pdb
def rpdb(port=4444):
class RemotePdb(remote_pdb.RemotePdb):
def do_shell(self, arg):
(define (factorial n)
;; tail recursion is fast, and often requires a helper function
(define (helper n product)
(if (< n 2)
product
(helper (- n 1) (* n product))))
(helper n 1))
;; Scheme looping structure
(do
@wware
wware / teensy_midi.ino
Last active July 1, 2016 20:18
Teensy MIDI controller
const int channel = 1;
const int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
int programs[] = {
1, // acoustic grand piano
9, // celesta
@wware
wware / README.md
Created August 1, 2016 19:17 — forked from leonardofed/README.md
A curated list of AWS resources to prepare for the AWS Certifications


A curated list of AWS resources to prepare for the AWS Certifications

A curated list of awesome AWS resources you need to prepare for the all 5 AWS Certifications. This gist will include: open source repos, blogs & blogposts, ebooks, PDF, whitepapers, video courses, free lecture, slides, sample test and many other resources.


Index: