Skip to content

Instantly share code, notes, and snippets.

@esromneb
esromneb / debounce.py
Created November 12, 2015 01:57
This is a proper debounce function, the way a electrical engineer would think about it.
import time
""" This is a proper debounce function, the way a electrical engineer would think about it.
This wrapper never calls sleep. It has two counters: one for successful calls, and one for rejected calls.
If the wrapped function throws an exception, the counters and debounce timer are still correct """
class Debounce(object):
def __init__(self, period):
@esromneb
esromneb / split.m
Created September 18, 2014 08:33
Split a vector of bounded length into individual return variables.
function [ o1, o2, o3, o4, o5, o6, o7, o8 ] = split( v )
%SPLIT Splits a vector of bounded length into individual return variables.
% Split() can handle arbitrarily long input vectors, but only a fixed
% number of output variables. @benathon
%
% Usage:
% vec = [1 2 3 4 5];
% [a,b,c,d,e] = split(vec);
% [f,g] = split(vec);
@esromneb
esromneb / g2rref.m
Last active July 21, 2022 12:28
matlab's rref function modified to operate in gf(2)
% This is a modified version of matlab's building rref which calculates
% row-reduced echelon form in gf(2). Useful for linear codes.
% Tolerance was removed because yolo, and because all values
% should only be 0 or 1. @benathon
function [A] = g2rref(A)
%G2RREF Reduced row echelon form in gf(2).
% R = RREF(A) produces the reduced row echelon form of A in gf(2).
%
% Class support for input A:
@esromneb
esromneb / gauss.m
Last active February 12, 2025 23:11
Gauss elimination and Gauss Jordan methods using MATLAB code
% Code from "Gauss elimination and Gauss Jordan methods using MATLAB"
% https://www.youtube.com/watch?v=kMApKEKisKE
a = [3 4 -2 2 2
4 9 -3 5 8
-2 -3 7 6 10
1 4 6 7 2];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@esromneb
esromneb / gist:8973217
Created February 13, 2014 11:00
Add this to your meteor project, and run it from the client. This will help you visualize your template re-renderings
redRenders = function () {
$('*').each(function(element){
$(this).css( "background-color", "red" );
});
}
@esromneb
esromneb / email.js
Last active February 12, 2016 18:58
Name this file server/email.js and then also add that to your .gitignore
// put me at server/email.js
Meteor.startup(function () {
var user = "user";
var password = "password";
var serverAndPort = "smtp.example.com:9999";
var string = 'smtp://' + user + ':' + password + '@' + serverAndPort;
process.env.MAIL_URL = string;
});
L.Control.Button = L.Control.extend({
options: {
position: 'bottomleft'
},
initialize: function (options) {
this._button = {};
this.setButton(options);
},
@esromneb
esromneb / userSettings.js
Created January 17, 2014 00:01
Drop this in /lib/ in your meteor app for a very simple user settings wrapper
function isArray(x) {
return _.isArray(x) && !EJSON.isBinary(x);
}
// pulled from "LocalCollection._makeLookupFunction"
var dotNotationFetch = function (key) {
var dotLocation = key.indexOf('.');
var first, lookupRest, nextIsNumeric;
if (dotLocation === -1) {
first = key;
@esromneb
esromneb / gist:7936719
Created December 12, 2013 22:30
Handy macros for byte operations as well as set and get bits
/**************************************************************************************************
* Filename: hal_defs.h
* Description: This file contains useful macros and data types
*
*
* Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@esromneb
esromneb / gist:6395247
Created August 30, 2013 23:29
Generate a "websocket style" length header
// only supports messages up to 65536 characters long
// takes a first param of byte_count and generates the correct "websocket style" header
// *header_len is set to the number of bytes used in header[]
void build_message_header(const size_t byte_count, char header[3], size_t* header_len)
{
size_t len = byte_count;
if( len < 126 )
{
header[0] = len & 0xff;
*header_len = 1;