Skip to content

Instantly share code, notes, and snippets.

@mbains
mbains / Modbus.cpp
Created July 30, 2017 04:33
STM32 Modbus Slave
/*
* File: Modbus.cpp
* Author: mbains
*
* Created on January 8, 2016, 5:21 PM
*/
#include "Modbus.h"
#define T35_TIMEOUT (5) //ms
write a python method to remove items from a dictionary based on the value
def removeByValue(d_dict, value_in):
''' delete item in d_dict where from value = value_in '''
pass
class Credit():
charges = []
history = {}
def __init__(value):
self.charges.append(value)
def balance():
print sum(self.charges)
@mbains
mbains / gist:3406184
Created August 20, 2012 17:59
Factory pattern using C++ templates
#include <iostream>
#include <map>
using namespace std;
class BaseClass{
public:
virtual int funk() {
return 0;
}
@mbains
mbains / gist:3342084
Created August 13, 2012 15:49
ending async callback hell with IcedCoffeeScript
#Simple example shows using await and defer of IcedCoffeeScript with setTimeout
#The calls within a code block are forced to wait until the previous defer action is completed.
#Program output:
# 1 going to sleep
# 2 going to sleep
# 2 done sleeping
# 1 done sleeping
test1 = ()->
@mbains
mbains / gist:3219002
Created July 31, 2012 18:05
Python strings should stay immutable.
#!/usr/bin/env python
from ctypes import CDLL
foo = "Fiesta"
bar = "Fiesta"
#Change foo with low level C
libc = CDLL('libc.so.6')
libc.strcpy(foo, "Nachos")
@mbains
mbains / signals.cpp
Created March 22, 2012 23:01 — forked from munro/signals.cpp
C++11 Signals
#ifndef __signals_h__
#define __signals_h__
#include <list>
#include <memory>
#include <iostream>
#include <functional>
namespace signals {
template<typename... Values> class Signal {
@mbains
mbains / server.js
Created February 22, 2012 20:43 — forked from mixonic/server.js
Node.js + Socket.io + Bash. A collaborative terminal for your browser.
//
// This server will start a bash shell and expose it
// over socket.io to a browser. See ./term.html for the
// client side.
//
// You should probably:
//
// npm install socket.io
// curl -O https://github.com/LearnBoost/Socket.IO/raw/master/socket.io.min.js
//