This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 | |
| |... | |
|--------------| | |
| | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import json | |
import requests | |
import click | |
def read_description(url): | |
"""Read json from url. | |
:param url: url to access |
NewerOlder