Skip to content

Instantly share code, notes, and snippets.

View vitiral's full-sized avatar

Rett Berg vitiral

  • Google
  • Denver, CO
View GitHub Profile
@vitiral
vitiral / allduino.cpp
Last active August 29, 2015 14:05
This code gets over 12 Hz transfer rates on the spark core (without any delays or hangs)
/**
* Better strncpy
* Example code:
* char buf[100];
* uint16_t len = 100;
* char *place = buf;
* len = bstrncpy(&place, "hello\n", len);
* len = bstrncpy(&place, "another hi\n", len);
* input:
@vitiral
vitiral / Timer
Created October 2, 2014 01:27
Timer class for timings
def test_timer(timer, duration = 1):
timer.enable()
time.sleep(1)
timer.disable()
print(timer.get_elapsed())
timer = Timer()
test_timer(timer)
class Timer(object):
def __init__(self, time=time.time):
self.time = time
@vitiral
vitiral / builtins.py
Last active August 29, 2015 14:09
Functions that should be in the python builtins module
from enum import Enum
def enum(name, attrs=None):
'''enum generator function
Creates an Enum type. attrs can be: set, list, tuples or a dictionary.
The behavior is as follows:
- dictionaries and lists/tuples of the form [(name, key), (name2, key2), ...] will behave
as expected. (dictionaries will have their items() method called
- sets will be converted to zip(sorted(attrs), range(len(attrs)))
- lists/tuples without embeded tuples will do the same without sorting
@vitiral
vitiral / get_platform.py
Last active August 29, 2015 14:10
python code to get all the information about the platform into a dictionary
# python 3
import os
import platform
import ctypes
import re
import subprocess
import psutil
def processor():
'''Get type of processor
@vitiral
vitiral / imp_anywhere.py
Created January 6, 2015 21:45
python import from anywhere
import imp
module = imp.find_module('path/to/module')
module = imp.load_module('module_name', *module)
@vitiral
vitiral / progress.py
Last active August 29, 2015 14:15
A Simple Progress Bar to use in the command line
#!/usr/bin/python
'''
Progress Bar - A Simple Progress Bar to use in the command line
Written in 2015 by Garrett Berg <garrett@cloudformdesign.com>
© Creative Commons 0
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. THIS SOFTWARE IS DISTRIBUTED WITHOUT ANY WARRANTY.
<http://creativecommons.org/publicdomain/zero/1.0/>
@vitiral
vitiral / LICENSE.txt
Last active August 29, 2015 14:15
Creative Commons 0 License
Description
Written in 2015 by Garrett Berg <garrett@cloudformdesign.com>
© Creative Commons 0
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. THIS SOFTWARE IS DISTRIBUTED WITHOUT ANY WARRANTY.
<http://creativecommons.org/publicdomain/zero/1.0/>
@vitiral
vitiral / __init__.py
Last active August 29, 2015 14:15
Functions that should be standard to pandas dataframe objects
We couldn’t find that file to show.
@vitiral
vitiral / ui_led_example4--p1.cpp
Last active January 15, 2016 10:53
usertools ui_led_example4 explained -- part1
#include <ui.h> // include protothread library
#define LEDPIN 13 // LEDPIN is a constant
uint16_t sub_time = 0; // subtracts time from LED periods
void toggleLED() {
boolean ledstate = digitalRead(LEDPIN); // get LED state
ledstate ^= 1; // toggle LED state using xor
digitalWrite(LEDPIN, ledstate); // write inversed state back
@vitiral
vitiral / ui_led_example5--p2.cpp
Last active January 15, 2016 10:54
ui_led_example5--p2
enum MYTHREADS{
LED1,
LED2
};
enum MYFUNCS{
REINIT
};
enum MYVARS{