Skip to content

Instantly share code, notes, and snippets.

class MultiDragDropTreeView(DragDropTreeView):
'''TreeView that captures mouse events to make drag and drop work properly'''
def __init__(self):
super(MultiDragDropTreeView, self).__init__()
self.connect('button_press_event', self.on_button_press)
self.connect('button_release_event', self.on_button_release)
self.defer_select = False
<!doctype html>
<html><head>
<script>
function init(){
var canvas = document.getElementById('canvas')
var width = canvas.width = window.innerWidth-10
var height = canvas.height = window.innerHeight-10
var c = canvas.getContext('2d');
@kevinmehall
kevinmehall / gist:1223301
Created September 16, 2011 22:22
USB Arduino demo
#include <UsbSimple.h>
void setup(){
USB.begin();
}
void loop(){
USB.refresh();
USB.set(0, analogRead(5));
@kevinmehall
kevinmehall / gist:1223343
Created September 16, 2011 22:45
Buttons / LEDs
void setup(){
pinMode(6,INPUT); // Button
digitalWrite(6, HIGH); // Enable pull-up on pin 6
pinMode(8,OUTPUT); // LED
}
int counter = 0;
int state = 0;
void loop(){
int button = digitalRead(6);
@kevinmehall
kevinmehall / gist:1224653
Created September 18, 2011 02:47
AlJazeera English Live with rtmpdump and mplayer (17 September 2011)
rtmpdump -v -r rtmp://livestfslivefs.fplive.net/aljazeeraflashlive-live -y "aljazeera_eng_high?videoId=883816736001&lineUpId=&pubId=6650033.03001&playerId=751182905001&affiliateId=" -W "http://admin.brightcove.com/viewer/us20110916.1045/BrightcoveBootloader.swf" -p "http://english.aljazeera.net/watch_now/" -a "aljazeeraflashlive-live?videoId=883816736001&lineUpId=&pubId=6650033.03001&playerId=751182905001&affiliateId=" | mplayer -
@kevinmehall
kevinmehall / gist:1335347
Created November 2, 2011 23:57
PWM on Xmega
#include "usb.h"
// PORT C
#define PWM1 (1<<0)
#define PWM2 (1<<1)
int main(void){
sei();
@kevinmehall
kevinmehall / gist:1338529
Created November 4, 2011 02:30
Quadrature Encoder with the Xmega event system
#include "usb.h"
// PORT C
#define QDEC1 (1<<2)
#define QDEC2 (1<<3)
int main(void){
sei();
@kevinmehall
kevinmehall / packetbuf.c
Created May 11, 2012 22:11
FIFO ring buffer for USB packets on xmega
// Bufferred BULK streaming
// http://nonolithlabs.com
// (C) 2011 Kevin Mehall (Nonolith Labs) <km@kevinmehall.net>
//
// Licensed under the terms of the GNU GPLv3+
#include "packetbuffer.h"
// CEE to PC buffer
Ringbuf in_ring;
@kevinmehall
kevinmehall / async_replace.coffee
Created September 14, 2012 22:27
Async find/replace in CoffeeScript
# Replace parts of `string` matching regex `pattern` with the callback value of an
# async function `fn`, which receives the regex match object and callback. Calls `cb` with
# final string when complete.
asyncReplace = (string, pattern, fn, cb)->
console.assert(pattern.global, "asyncReplace pattern must be global (g flag)")
outChunks = []
lastIndex = 0
pendingCb = 0
@kevinmehall
kevinmehall / instructions.md
Created October 20, 2012 23:42
Compiling the Atmel-patched AVR toolchain