This file contains 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
/// Pseudo-inverse of a matrix. There may be a more efficient solution for square matrices; this is a general one. | |
/// Tolerance less than epsilon*10 may cause numerical instability. | |
template <auto R, auto C, typename S> | |
[[nodiscard]] Eigen::Matrix<S, C, R> pinv(const Eigen::Matrix<S, R, C>& a, const S tolerance = std::numeric_limits<S>::epsilon() * 10) | |
{ | |
const Eigen::JacobiSVD<Eigen::Matrix<S, R, C>> svd(a, Eigen::ComputeFullU | Eigen::ComputeFullV); | |
Eigen::Matrix<S, C, R> si; | |
si.setZero(); | |
for (int i = 0; i < svd.singularValues().size(); ++i) | |
{ |
This file contains 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
#!/bin/bash | |
# https://gist.github.com/pavel-kirienko/32e395683e8b7f49e71413aebf5e1a89 | |
# Pavel Kirienko <[email protected]> | |
HELP="Register slcan-enabled serial-to-CAN adapters as network interfaces. | |
Usage: | |
`basename $0` [options] <tty0> [[options] <tty1> ...] | |
Interface indexes will be assigned automatically in ascending order, i.e., the | |
first device will be mapped to slcan0, second to slcan1, and so on. |
This file contains 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 | |
# Bulk usage: | |
# find . -name '*.[ch]pp' -exec bash -c 'recomment.py < "{}" > "{}.out" ; mv "{}.out" "{}"' \; | |
import sys, re | |
RE_REPLACE = re.compile(r"(?m)^(\s*?) ?\*(.*)") | |
def replace_one(match) -> str: | |
use_doc = bool(match[1]) |
This file contains 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
# Capture high-frame-rate, high-resolution video of the desktop using ffmpeg. | |
# The key options are: -c:v libx264 -f flv -vb 1000M -deadline realtime -cpu-used 12 | |
# Without these, the output video peaks at ~5 fps or so. | |
ffmpeg -video_size 3840x2080 -f x11grab -i :0.0+3840,0 -c:v libx264 -f flv -vb 1000M -deadline realtime -cpu-used 12 output.mp4 -y |
This file contains 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
# By default, X-Box 360-compatible controllers are detectable but dysfunctional because they expect the host | |
# to send a particular USB control transfer with some sort of initialization command. | |
# This udev rule will invoke a trivial Python script automatically when the gamepad is connected that emits | |
# the required initialization command. | |
# | |
# Integration: | |
# 1. Put this rule into /etc/udev/rules.d/51-xbox-gamepad.rules | |
# 2. Install pyusb for the root's Python: sudo pip install pyusb | |
# 3. Reload udev rules as root: udevadm control --reload-rules && udevadm trigger | |
# |
This file contains 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
#!/bin/bash | |
# Convert all video files in the current directory into gifs. | |
# Silently overwrite existing files. | |
# This is useful for working with matplotlib animations. | |
for src in *.mp4 | |
do | |
bn="${src%.*}" | |
echo "$src $bn" | |
ffmpeg -y -i "$src" "${bn}.gif" || exit 1 | |
done |
This file contains 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
# The part .data=0x08000000 should be replaced with the correct base offset of the ROM. | |
# The value 0x08000000 is valid for STM32. | |
arm-none-eabi-objcopy -I binary -O elf32-little --change-section-address .data=0x08000000 input.bin output.elf |
This file contains 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
def run(): | |
rpm_setpoint = 0 | |
going_down = False | |
step = 2 | |
def update(): | |
nonlocal rpm_setpoint | |
nonlocal going_down | |
rpm_setpoint += (-step if going_down else step) | |
broadcast(uavcan.equipment.esc.RPMCommand(rpm=[rpm_setpoint])) | |
if going_down: |
This file contains 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
#!/bin/bash | |
# | |
# Backup server web interface (CGI script). | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: |