Skip to content

Instantly share code, notes, and snippets.

@jkbjh
jkbjh / python-pid_controller
Created October 25, 2017 14:54 — forked from chaosmail/python-pid_controller
Simple PID Controller
def pid_controller(y, yc, h=1, Ti=1, Td=1, Kp=1, u0=0, e0=0)
"""Calculate System Input using a PID Controller
Arguments:
y .. Measured Output of the System
yc .. Desired Output of the System
h .. Sampling Time
Kp .. Controller Gain Constant
Ti .. Controller Integration Constant
Td .. Controller Derivation Constant
@jkbjh
jkbjh / make_julia_deb.sh
Last active September 22, 2021 09:57
create debian package from julia (julialang) binary
#!/bin/bash
TARGETLINK=https://julialang-s3.julialang.org/bin/linux/x64/1.6/julia-1.6.2-linux-x86_64.tar.gz
VERSION=1.6.2
CURDIR=$(pwd)
set -e
set -x
ARCHIVE=julia-$VERSION.tar.gz
wget $TARGETLINK -O $ARCHIVE
UNCOMPRESSED_SIZE=$(zcat $ARCHIVE | wc -c)
#!/usr/bin/env python
import subprocess
import socket
from contextlib import closing
import threading
import time
import os
import signal
import argparse
@jkbjh
jkbjh / ce_opt.py
Last active October 25, 2019 11:46
# cross-entropy optimization
import numpy as np
import tqdm
def ce_minimize(X_mean, X_std, eval_loss, iterations=100, sample_size=25, keep_samples=10):
assert 0 < sample_size
assert 0 < keep_samples and keep_samples < sample_size
# Alg settings:
@jkbjh
jkbjh / ipy_dark.py
Last active March 11, 2022 12:29
interactive python dark magic
"""Dark magic for interactive python."""
import builtins
import time
def ipy_here(leak_variables=True):
import IPython
import inspect
parent_frame = inspect.currentframe().f_back
@jkbjh
jkbjh / pip_require_this.py
Last active August 18, 2020 08:15
Get PIP Requirements for current folder. Hacky.
import importlib
import subprocess
import re
import os
import joblib
from joblib import parallel_backend, Parallel, delayed
found_imports = sorted(list(set([x.lstrip().rstrip() for x in subprocess.check_output("findimports -p -l 1 |grep -v ':' |sort -u", shell=True).decode("utf-8").rstrip().lstrip().split("\n")])))
installed_packages = subprocess.check_output('pip list | tail -n +3 | cut -d" " -f1', shell=True).decode("utf-8").rstrip().lstrip()
;;; diction.el --- minor mode to interface the command diction
;;; Copyright Sven Utcke <Sven.Utcke@gmx.de>
;; Emacs Lisp Archive Entry
;; Filename: diction.el
;; Version: $Id: diction.el,v 1.8 2005/09/29 12:55:52 utcke Exp $
;; Keywords: diction, style
;; Author: Sven Utcke <Sven.Utcke@gmx.de>
;; Maintainer: Sven Utcke <Sven.Utcke@gmx.de>
# a selection of small numpy helper functions
import joblib
def apply_along_axes(func, data, axes):
"""
apply function along axes and use joblib parallel to execute the function on the selections.
might result in a large allocation for reconstructing the result.
only makes sense if the sub-executions are sufficiently costly.
"""
import collections
JointInfo = collections.namedtuple(
"JointInfo",
[
"index",
"name",
"type",
"q_index",
#!/bin/bash
set -e
set -x
# you can directly run this with: bash <(curl -Ls "https://gist.githubusercontent.com/jkbjh/c83e5bf6d708f590f77ccdd6b2ef0a40/raw/mujoco-210-user-install.sh?$(date +%s)")
# (the date query parameter is to to prevent caching when downloading through curl.)
export START_DIR=$(pwd)
export MJ_DIR=$HOME/.mujoco
mkdir -p $MJ_DIR
pushd $MJ_DIR
curl -LJ 'https://github.com/deepmind/mujoco/releases/download/2.1.0/mujoco210-linux-x86_64.tar.gz' -o $MJ_DIR/mujoco210_linux.tgz