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 / 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
@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
| |...
|--------------|
| |
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 / 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):
@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 / 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;
f1 = lambda x: 1./np.exp(0.1*(x + 80.))
f2 = lambda x: -.26*(x+58)
def weight(i, fs):
return lambda x: np.exp(fs[i](x)) / np.sum([np.exp(f(x)) for f in fs])
def softmax(fs):
return lambda x: np.sum([f(x)*weight(i,fs)(x) for i,f in enumerate(fs)])
softmax([f1,f2])(np.linspace(-80,0))
import numpy as np
import tf.transformations as tft
def quat_to_array(msg):
return np.array([msg.x, msg.y, msg.z, msg.w])
def vec_to_array(msg):
return np.array([msg.x, msg.y, msg.z])
def from_pose_msg(msg):
@stfuchs
stfuchs / function_lookup.cpp
Created October 12, 2017 11:39
Function calls from string config
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <unordered_map>
std::vector<std::string> split(const std::string& value, char delim)
{
std::vector<std::string> res;
@stfuchs
stfuchs / packing_my_robot_body.py
Created October 5, 2017 12:07
solving a knapsack problem
#! /usr/bin/env python
import json
import requests
import click
def read_description(url):
"""Read json from url.
:param url: url to access