Skip to content

Instantly share code, notes, and snippets.

@fbstj
fbstj / ext.cs
Last active December 12, 2015 10:39
using System;
using System.IO.Ports;
using System.Threading;
using System.Globalization;
namespace Terminal
{
static class Program
{
static void Main(string[] s)
@fbstj
fbstj / ringbuffer.h
Created February 15, 2013 09:11
A ring-buffer generation utility
/*
simple ring buffer
*/
#ifndef RING_BUFFER_H_
#define RING_BUFFER_H_
enum E_RING_BUFFERS { e_RING_OK = 0, e_RING_EMPTY, e_RING_FULL, e_RING_ERROR };
#define T_RING(T, tag, len)\
struct tag { T buffer[len]; unsigned int head, tail; };\
def signed(chars, index = 0, length = 16):
"""convert a `length/4` character hex string into a signed `length`-bit number"""
v = int(chars[index:][:(length / 4)], 16)
return v if v < (1 << (length - 1)) else v - (1 << length)
// count down to zero
num -= !!(num - 1);
// count up to MAX
num += (num < MAX);
@fbstj
fbstj / RepeatButton.py
Created July 15, 2013 13:18
a tkinter (ttk) button extension that repeatedly invokes the command whilst the button is held down, includes a simple exponential acceleration
from Tkinter import *
from ttk import *
class RepeatButton(Button):
def __init__(self, _, **kw):
Button.__init__(self, _)
self.config(**kw)
self.bind('<Button-1>', self._start)
self.bind('<ButtonRelease-1>', self._end)
def _start(self, event):
self._delay = 1500
@fbstj
fbstj / HTMLOFF.js
Created September 6, 2011 21:26
HTML object notation, maps JSON to HTML tables and lists
// converts HTML tables and lists into JSON/js objects and arrays
function HTMLOFF(el)
{//reverses the effects of HTMLON
function tbl(root)
{
var o = {}, rows = $('tbody', root).first().children(),
row = rows.first()
for(var j = 0; j < rows.length; j++)
{