Skip to content

Instantly share code, notes, and snippets.

View stfuchs's full-sized avatar

Steffen Fuchs stfuchs

  • Zebra Technologies
  • San Jose, CA
View GitHub Profile
@stfuchs
stfuchs / max_buffer.cpp
Last active April 25, 2018 18:43
Container to buffer N max elements
#include <iostream>
#include <string>
#include <algorithm>
template<class Key, class T>
class MaxBuffer
{
typedef std::pair<Key, T> value_type;
typedef typename std::vector<value_type>::iterator iterator;
typedef typename std::vector<value_type>::const_iterator const_iterator;
typedef typename std::vector<value_type>::reverse_iterator reverse_iterator;
@stfuchs
stfuchs / transforms.py
Last active June 21, 2018 18:03
simple library for homogeneous transformation using quaternions
# Standard Library
from math import pi as M_PI
from math import cos, sin, sqrt
class Vector(object):
def __init__(self, x, y, z):
self.x = x
self.y = y
@stfuchs
stfuchs / camel_and_snake.py
Last active November 30, 2018 01:32
Convert between camel and snake
# Credit:
# https://stackoverflow.com/questions/19053707/converting-snake-case-to-lower-camel-case-lowercamelcase
# https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case/32064723
import re
def camel_to_snake(s):
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', re.sub('(.)([A-Z][a-z]+)', r'\1_\2', s)).lower()
def snake_to_camel(s):
import pandas as pd
def histogram(values, bins=100, xmin=None, xmax=None, xstr=lambda x: '%s' % x, linewidth=120, symbol='B0'):
sym = {
'B1': u'\u2591', # Light shade
'B2': u'\u2592', # Medium shade
'B3': u'\u2593', # Dark shade
'B4': u'\u2588', # Full Block
'B0': u'\u25a0'} # Black square
@stfuchs
stfuchs / malloc.cpp
Last active November 2, 2021 17:04
simple malloc and free implementation
/*
Imagine this is a block of memory. Goal is to give users access to parts of this global shared resource.
They can access X memory locations by doing `malloc(X)` and can free it by returning the pointer they were handed
Goal of the question is to fill in class Allocator without using any additional class variables.
|--------------|0
| |...
|--------------|
| |
@stfuchs
stfuchs / vector.cpp
Last active June 10, 2021 21:12
Implement a simple vector class
#include <cstdint>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
// use malloc and free instead of new and delete
// malloc take one argument that is a size in bytes of memory needed