Skip to content

Instantly share code, notes, and snippets.

@hangst
hangst / mwc.sh
Last active September 19, 2020 14:06
Bundles and minifies Material Web Components
folder=mwc_$(date +%s%N)
mkdir $folder
cd $folder
sudo apt-get -qq --assume-yes install minify npm
eval npm install \
@material/mwc-button \
@material/mwc-checkbox \
@material/mwc-circular-progress \
@hangst
hangst / key_solver.py
Last active April 7, 2020 13:59
Solution to the key problem
#!/usr/bin/env python
"""
Problem statement: Find the three digit number
147 - One digit is right but in the wrong place
189 - One digit is right and in its place
964 - Two digits are correct but both are in the wrong place
523 - All digits are wrong
286 - One digit is right but in the wrong place
"""
@hangst
hangst / toyaml.js
Last active April 20, 2020 08:16
Stringifies Javascript object to YAML
function toYAML(src, pad=0, nested_list=false){
function f(i, nested_list, size){
if (i == 0 && !nested_list) return `\r\n${" ".repeat(size)}`
else if(i != 0) return `${" ".repeat(size)}`
return ""
}
var tabsize = 2
var dst = ""
if(Array.isArray(src)){
src.forEach(function(s, i){
@hangst
hangst / build_ros_neotic.sh
Last active April 24, 2020 06:08
Build ROS Neotic + Python3
export ROS_PYTHON_VERSION=3
sudo apt-get install python3-rosdep2 python3-rosinstall-generator python3-wstool
rosinstall_generator ros_comm --rosdistro noetic --deps --tar > ros.rosinstall
wstool init -j8 src ros.rosinstall
rosdep install -r -y --from-paths src --ignore-src --rosdistro noetic
catkin_make_isolated --install -DCATKIN_ENABLE_TESTING=0
# rosinstall_generator common_msgs geometry navigation --rosdistro noetic --deps --tar > extras.rosinstall
# wstool merge -t src extras.rosinstall
# wstool update -t src
@hangst
hangst / compile_kernel.sh
Last active October 21, 2023 14:40
Compile mainline Linux kernel and boot on Amlogic Meson S905 through USB
# linux-meson.com/doku.php#howto
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image dtbs
mkimage -A arm64 -O linux -T kernel -C none -a 0x1080000 -e 0x1080000 -n linux-next -d arch/arm64/boot/Image ../uImage
cp arch/arm64/boot/dts/amlogic/meson-gxbb-wetek-play2.dtb ../uImage BOOT_PARTITION
# ROOTFS_PARTITION can be any arm64 Linux root filesystem
@hangst
hangst / setup_m55.py
Last active July 7, 2020 17:08
Configure Corsair M55 without iCUE
#!/usr/bin/env python3
import argparse
import usb
def find_interface(dev):
for config in dev:
for iface in config:
ep_out, ep_in = None, None
for ep in iface:
@hangst
hangst / cython_executable.sh
Last active July 8, 2020 15:41
Compile executable Python
cython3 --embed src.py --output-file dst.c
g++ dst.c -I/usr/include/python -L/usr/lib/x86_64-linux-gnu -lpython
@hangst
hangst / patch_uvc_tk1_realsense.sh
Last active September 14, 2020 06:56
Patch UVC video driver for Jetson TK1 + Intel RealSense
wget http://developer.download.nvidia.com/embedded/L4T/r21_Release_v5.0/source/kernel_src.tbz2
tar -xpf kernel_src.tbz2
@hangst
hangst / flutter_ubuntu_setup.sh
Last active October 16, 2020 03:34
Flutter Ubuntu without Android Studio
sudo apt-get remove openjdk-*
sudo apt-get install openjdk-8-jdk-headless
# Download from https://developer.android.com/studio#command-tools
wget https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip
unzip commandlinetools-linux-*_latest.zip
mkdir ~/Android
mv tools ~/Android
echo "export ANDROID=$HOME/Android" >> ~/.bashrc
@hangst
hangst / nvidia_smi_minimal.sh
Created April 19, 2021 02:56
Minimal display with nvidia-smi
nvidia-smi -lms 500 | grep Default --line-buffered | cut -c36-70