Skip to content

Instantly share code, notes, and snippets.

@pabsan-0
pabsan-0 / find_up_macros.bash
Created March 22, 2023 07:57
Snippets to look for files in parent directories
## https://unix.stackexchange.com/a/22215
## find_up filename
find_up () {
path=$(pwd)
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
path=${path%/*}
done
echo "$path"
}
@pabsan-0
pabsan-0 / .tmuxinator.yml
Last active May 11, 2023 11:10
tmuxinator minimal example
#! /usr/bin/env -vS tmuxinator start -p
# rename to .tmuxinator.yml and run `tmuxinator start`
# OR run `tmuxinator start -p custom_filename.yml`
# OR make executable and run with shebang
name: my-session
on_project_start: cd ~
on_project_exit: tmux kill-session -t my-session
windows:
@pabsan-0
pabsan-0 / cross_valid.py
Created February 26, 2023 15:26
sklearn cross validation example with KFold
from sklearn.datasets import load_iris
import pandas as pd
import numpy as np
from sklearn.model_selection import KFold
from sklearn import metrics
from sklearn.linear_model import LinearRegression
df = load_iris(return_X_y=True, as_frame=True)
X = df[0]
@pabsan-0
pabsan-0 / gst-opencv
Last active March 31, 2023 06:09
Install instructions for opencv with gstreamer support
OPENCV_VER="master"
TMPDIR=$(mktemp -d)
# Build and install OpenCV from source.
cd "${TMPDIR}"
git clone --branch ${OPENCV_VER} --depth 1 --recurse-submodules --shallow-submodules https://github.com/opencv/opencv-python.git opencv-python-${OPENCV_VER}
cd opencv-python-${OPENCV_VER}
export ENABLE_CONTRIB=1
export ENABLE_HEADLESS=0
# We want GStreamer support enabled.
#! /usr/bin/bash
#
# This bash quickie lists your connected v4l2 cameras by parsing the output of `v4l2-ctl --list-devices`.
# Useful when playing w/ external cameras since replugging will usually modify its /dev/videoX location
#
# Example output
# ```
# C:
#
# #define CAM_0 "/dev/video2"
@pabsan-0
pabsan-0 / gst-interlatency-parser.bash
Last active August 10, 2022 12:00
Parses the stderr from RidgeRun's Gst-Shark interlatency profiler
#! /usr/bin/bash
# This bash scripts takes the stderr from RidgeRun's Gst-Shark interlatency
# tracer and parses its output to build some tables averaging results.
#
# Install gst shark and wrap your pipeline as:
# $ GST_DEBUG="GST_TRACER:7" GST_TRACERS="interlatency" \
# gst-launch-1.0 videotestsrc ! videoconvert ! autovideosink \
# 2> tracer.log
#
@pabsan-0
pabsan-0 / gstreamer-webcam-array.sh
Created August 9, 2022 12:59
Display of 4 cameras with gstreamer
#! /usr/bin/bash
# This script to plot an array of 4 cameras with gstreamer
#
# To have them in sequence, define d0-d3 in increasing order, then circle your
# hand through all cameras. Change d0-d3 to the order your hand appears in.
# Then, you'll get a spatially coherent display of cameras next to each other.
# Ids from /dev/videoXX, get with `$ gst-device-monitor-1.0 | grep v4l2src`
d0=7
@pabsan-0
pabsan-0 / mountain_car_ac.py
Created September 23, 2021 18:34
Solving mountain car with linear value function approximation and softmax actor-critic
'''
Actor critic learning of linearized mountain car.
Critic: Linear action-value with function approximation, TD(0).
Actor: gradient ascent with softmax policy, based on action-value function.
'''
import matplotlib
import numpy as np
import gym