Skip to content

Instantly share code, notes, and snippets.

@octavifs
octavifs / Dockerfile
Created May 7, 2021 18:08
Deep Learning in Production Part 1: Reproducible Environments
FROM ubuntu:20.04
ENV LANG=C.UTF-8 DEBIAN_FRONTEND=noninteractive
ENV PATH /opt/conda/bin:$PATH
# Install conda
RUN apt-get update --fix-missing && \
apt-get install --no-install-recommends -y curl ca-certificates && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o miniconda.sh \
@octavifs
octavifs / altair_static_interactive.ipynb
Last active July 23, 2020 14:57
nbconvert template for altair interactive graph rendering
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@octavifs
octavifs / tmux_htop_local_install.sh
Last active March 12, 2024 16:02
Install tmux and htop statically without root
#!/bin/sh
# Script for installing tmux & htop on systems where you don't have root access.
# Inspired by https://gist.github.com/ryin/3106801
# tmux will be installed in $HOME/local/bin.
# htop will be installed in $HOME/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
@octavifs
octavifs / heap.py
Created June 14, 2013 01:54
Heap class that implements (almost) all the heapq standard python interface. Added some doctests and magic methods for convenience.
import heapq
class Heap(object):
"""
Heap class implementing the heapq interface + some magic methods.
Unit Tests:
>>> h = Heap([1,5,78,2,5,78])
>>> h
Heap([1, 2, 78, 5, 5, 78])
@octavifs
octavifs / foreach.cpp
Last active December 18, 2015 04:58
foreach C++ macro. Takes a variable (will be an iterator. Don't instantiate!) and a container. Salvaged from http://stackoverflow.com/a/197926.
// Usage:
// foreach(it, container) {
// CONTAINER_VALUE_TYPE v = *it
// ...
// }
//
#ifndef FOREACH_MACRO
#define FOREACH_MACRO
#define VAR(V,init) __typeof(init) V=(init)
#define FOREACH(I,C) for(VAR(I,(C).begin());I!=(C).end();I++)
@octavifs
octavifs / split.cpp
Created June 7, 2013 11:18
Split c++ string by char delimiter. Return vector with tokens. This solution does not skip empty tokens. Based on http://stackoverflow.com/a/236803
#include <string>
#include <sstream>
#include <vector>
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
@octavifs
octavifs / std::map_to_boost::python::dict.cpp
Last active March 9, 2021 03:04
Converts C++ std::map to boost::python::dict
// Converts a C++ map to a python dict
template <class K, class V>
boost::python::dict toPythonDict(std::map<K, V> map) {
typename std::map<K, V>::iterator iter;
boost::python::dict dictionary;
for (iter = map.begin(); iter != map.end(); ++iter) {
dictionary[iter->first] = iter->second;
}
return dictionary;
}
@octavifs
octavifs / std::vector_to_boost::python::list.cpp
Last active June 7, 2017 12:32
Converts C++ std::vector to boost::python::list
// Converts a C++ vector to a python list
template <class T>
boost::python::list toPythonList(std::vector<T> vector) {
typename std::vector<T>::iterator iter;
boost::python::list list;
for (iter = vector.begin(); iter != vector.end(); ++iter) {
list.append(*iter);
}
return list;
}