Skip to content

Instantly share code, notes, and snippets.

Joe ST fbstj

Block or report user

Report or block fbstj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fbstj
fbstj / RepeatButton.py
Created Jul 15, 2013
a tkinter (ttk) button extension that repeatedly invokes the command whilst the button is held down, includes a simple exponential acceleration
View RepeatButton.py
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
View gist:5934389
// count down to zero
num -= !!(num - 1);
// count up to MAX
num += (num < MAX);
View signed.py
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)
@fbstj
fbstj / ringbuffer.h
Created Feb 15, 2013
A ring-buffer generation utility
View ringbuffer.h
/*
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; };\
View ext.cs
using System;
using System.IO.Ports;
using System.Threading;
using System.Globalization;
namespace Terminal
{
static class Program
{
static void Main(string[] s)
@fbstj
fbstj / ini.c
Last active Dec 11, 2015
ini file parsing
View ini.c
#include <string.h>
#include <stdio.h>
enum ini_parts {
ini_section, ini_key, ini_value,
ini_section_start = '[', ini_section_end=']',
ini_key_value = '=',
ini_comment = ';'
};
@fbstj
fbstj / gist:2216990
Created Mar 27, 2012
Some abstract algebra interfaces/structs for Csharp
View gist:2216990
This gist has moved to FallingBullets/lib.cs on branch algebra
@fbstj
fbstj / Components.cs
Created Mar 23, 2012
some extension methods for Control
View Components.cs
public static int Value(this Control _, NumberStyles s, IFormatProvider p)
{
int d;
if (int.TryParse(_.Text, s, p, out d))
return d;
return 0;
}
public static double Value(this Control _)
{
double d;
@fbstj
fbstj / greystring.js
Created Jan 11, 2012
detects strings who's characters are in a Grey-code sequence
View greystring.js
// detects strings whos bytes are greycoded
function greystring(str){
var a, b
function bitcount(v){
var c;
for (c = 0; v; c++)
v &= v - 1;
return c;
}
for(var i = 1; i < str.length; i++)
@fbstj
fbstj / Buffer.js
Created Jan 7, 2012
some extension methods and utility functions for ArrayBuffer
View Buffer.js
var Buffer = {
_for: function(n, cb){ for(var i = 0; i < n; i++) cb(i) },
_to: function(x, size, cb) {
var v = new DataView(x), out = [], l = x.byteLength/size
this._for(l, function (i) { out[i] = v[cb](i*size) })
return out
},
toBytes: function(b) { return this._to(b, 1, 'getUint8') },
toWords: function(b) { return this._to(b, 2, 'getUint16') },
You can’t perform that action at this time.