Skip to content

Instantly share code, notes, and snippets.

@niun
niun / us_international.py
Last active September 25, 2024 02:29
Convert windows keyboard XML files from kbdlayout.info to Vial keymap python files
# coding: utf-8
"""Example result of vial_import_win_layout.py"""
keymap = {
"KC_1": '! ¹\n1 ¡', # Keyboard 1 and Bang, Win: VK_1, AT-101 position: 2
"KC_2": '@ \n2 ²', # Keyboard 2 and At, Win: VK_2, AT-101 position: 3
"KC_3": '# \n3 ³', # Keyboard 3 And Hash, Win: VK_3, AT-101 position: 4
"KC_4": '$ £\n4 ¤', # Keyboard 4 and Dollar, Win: VK_4, AT-101 position: 5
"KC_5": '% \n5 €', # Keyboard 5 and Percent, Win: VK_5, AT-101 position: 6
"KC_6": '^ \n6 ¼', # Keyboard 6 and Caret, Win: VK_6, AT-101 position: 7

Raspberry Pi (Zero) as Network Adapter USB Gadget

HowTo Summary for the Host PC <- Ethernet over USB Cable -> Raspi connection with a Windows focus

Requires a Raspberry Pi with a DWC USB controller. Should work with Raspberry Pi Zero (v1, v1.3, W, WH, 2 W), A, A+, 3A+, 4B. Raspi 5 with firmware update sudo rpi-update is said to work also.

These guides have more details but are not updated for Raspberry Pi OS Bookworm which changed some network configuration related stuff (migrated to NetworkManager?):

@niun
niun / esp8266-03-result.md
Last active January 20, 2018 15:15
Test ESP8266 AT commandos

Connected to my ESP8266-ESP-03 with following baudrate settings

BAUD = 9600
BOOT_BAUD = 115200

esp8266_at_test.py prints this:

PINGING esp8266...
> AT

>

@niun
niun / time-from-internet.sh
Created July 15, 2016 17:19
show time from Internetz in shell, iso-8601
curl -G -s --data-urlencode "format=%FT%T%:z" http://www.timeapi.org/cet/now # www.timeapi.org cet is CET/CEST. Don't use cest
date --iso-8601='seconds' -d "$(curl -s http://www.timeapi.org/utc/now)" # www.timeapi.org use local timezone settings
date -d "$(curl -s http://www.timeapi.org/utc/now)" +"%FT%T (UTC%:z = %Z)" # not quite ISO with timezone illustration
date -d "$(curl -s http://www.timeapi.org/utc/now)" +"%A %d.%m.%Y, %T (UTC%:z = %Z)" # non-ISO, easy readable by a german with day of week
date --iso-8601='seconds' -d "$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')" # google.com
date --iso-8601='seconds' -d "$(cat </dev/tcp/time.nist.gov/13 | cut -d' ' -f2,3) UTC" # NIST
date --iso-8601='seconds' -d "$(cat </dev/tcp/de.pool.ntp.org/13)" # ntp pool project
@niun
niun / git-extract-file.markdown
Created November 13, 2015 14:35 — forked from ssp/git-extract-file.markdown
Extract a single file from a git repository

How to extract a single file with its history from a git repository

These steps show two less common interactions with git to extract a single file which is inside a subfolder from a git repository. These steps essentially reduce the repository to just the desired files and should performed on a copy of the original repository (1.).

First the repository is reduced to just the subfolder containing the files in question using git filter-branch --subdirectory-filter (2.) which is a useful step by itself if just a subfolder needs to be extracted. This step moves the desired files to the top level of the repository.

Finally all remaining files are listed using git ls, the files to keep are removed from that using grep -v and the resulting list is passed to git rm which is invoked by git filter-branch --index-filter (3.). A bit convoluted but it does the trick.

1. copy the repository to extract the file from and go to the desired branch

@niun
niun / remove-old-kernels.txt
Created July 27, 2015 11:30
Debian: Remove old kernel packages
http://tuxtweaks.com/2010/10/remove-old-kernels-in-ubuntu-with-one-command/
dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | grep -E "(image|headers)" | xargs sudo apt-get -y purge
@niun
niun / rsync-cheatsheet.txt
Last active June 27, 2024 14:06
rsync backup cheatsheet
rsync -raXi --size-only /path/to/folder-to-backup/ /destinations/path/to/folder-to-backup
same as
rsync -rlptgoDXi --size-only /path/to/folder-to-backup/ /destinations/path/to/folder-to-backup
same as
rsync -rlptgoDXi --size-only /path/to/folder-to-backup /destinations/path/to
-r recursive
-l preserve links
-p preserve permissions (also updates permission on not transferred files)
-t preserve time (also updates time on not transferred files)
@niun
niun / root-ro
Last active June 27, 2024 14:06
Read-only Root-FS with overlayfs for Raspian
#!/bin/sh
#
# Read-only Root-FS for Raspian
#
# Modified 2015 by Pascal Rosin to work on raspian-ua-netinst with
# overlayfs integrated in Linux Kernel >= 3.18.
#
# Originally written by Axel Heider (Copyright 2012) for Ubuntu 11.10.
# This version can be found here:
# https://help.ubuntu.com/community/aufsRootFileSystemOnUsbFlash#Overlayfs
@niun
niun / install-wimp-wine.txt
Last active August 29, 2015 14:12
install wimp >= 3.1 in wine
# Source: http://thinkpad-forum.de/threads/179658-Wine-Wimp
# The exe installer does not work.
# Workaround: extract msi from exe, install msi.
wine WiMP-3.1.0.1858-NO.exe /extract
wine msiexec /i 8840086/WiMP-3.1.0.1858-NO.msi
@niun
niun / rpi-make-dt-blob.sh
Created October 24, 2014 14:33
Create custom device tree blob to configure Raspberry Pi pins on early boot time
apt-get install device-tree-compiler
wget https://raw.githubusercontent.com/raspberrypi/documentation/master/configuration/images/dt-blob.dts
# for example, set P1:26 (BCM pin 7) to active low (on Raspi B Rev2.0, in dts file from August):
awk 'NR==104{print " pin@p7 { function = \"output\"; termination = \"pull_down\"; }; // SPI_CE1_N (P1:26)"}1' dt-blob.dts > dt-blob-mod.dts
dtc -I dts -O dtb -o /boot/dt-blob.bin dt-blob-mod.dts