Skip to content

Instantly share code, notes, and snippets.

View larsch's full-sized avatar

Lars Christensen larsch

View GitHub Profile
@larsch
larsch / install-arch-linux-rpi-zero-w.sh
Created July 6, 2017 06:05
Install Arch Linux ARM for Raspberry Pi Zero W on SD Card (with commands to configure WiFi before first boot).
#!/bin/sh -exu
dev=$1
cd $(mktemp -d)
function umountboot {
umount boot || true
umount root || true
}
# RPi1/Zero (armv6h):
@larsch
larsch / archlinuxarm-on-nanopi-r2s.md
Created October 10, 2020 10:48
Installing Arch Linux AArch64 on the NanoPi R2S

Installing Arch Linux AArch64 on the NanoPi R2S

There is current no support for the NanoPi R2S in ArchLinuxArm, but it's possible to run it using the generic aarch64 installation.

Prepare sd-card/image

  1. Copy bootloader and uBoot from an armbian image using for the NanoPi R2S using dd (sectors 32 to 32767) everything before the partition, except the partition table).
  2. Create an ext4 partition on /dev/mmcblk0p1 at offset of 32768 sectors (16384 KiB):
Device         Boot Start      End  Sectors  Size Id Type
@larsch
larsch / create-arch-image-raspberry-pi-2.sh
Last active March 11, 2024 13:55
Shell script that creates a Arch Linux image for the Raspberry Pi 2. Downloads the latest distribution from archlinuxarm.org and creates the flash filesystems including boot partition. Partitions are aligned for typical SD cards and ext filesystem tuned accordingly.
#!/bin/sh -ex
losetup /dev/loop0 && exit 1 || true
image=arch-linux-$(date +%Y%m%d).img
wget -q -N http://archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
truncate -s 1G $image
losetup /dev/loop0 $image
parted -s /dev/loop0 mklabel msdos
parted -s /dev/loop0 unit s mkpart primary fat32 -- 1 65535
parted -s /dev/loop0 set 1 boot on
parted -s /dev/loop0 unit s mkpart primary ext2 -- 65536 -1
#include <avr/sleep.h>
// const int com[4] = { 10, 13, 14, 4 };
// const int com[4] = { 4, 14, 13, 10 };
// const int dig[8] = { 11, 15, 6, 8, 9, 12, 5, 7 };
// const int dig[8] = { 13, 17, 4, 6, 7, 14, 3, 5 };
// const int num[10] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f };
// int nmd[10] = {};
// int nmb[10] = {};
@larsch
larsch / PrecompiledHeader.cmake
Last active March 12, 2022 10:49
cmake module for setting up precompiled headers (MSVC & GCC)
# Function for setting up precompiled headers. Usage:
#
# add_library/executable(target
# pchheader.c pchheader.cpp pchheader.h)
#
# add_precompiled_header(target pchheader.h
# [FORCEINCLUDE]
# [SOURCE_C pchheader.c]
# [SOURCE_CXX pchheader.cpp])
#
@larsch
larsch / testpcap.c
Last active January 11, 2022 08:14
libpcap latency/break test
#include <pcap.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
pcap_t* pcap;
void* thread(void* arg) {
@larsch
larsch / vpnexec.sh
Last active November 8, 2020 17:49
Run firefox with Wireguard VPN using network namespaces
#!/bin/sh
exec ip netns exec vpn su user -c "$*"
option(WITH_VLD "With Visual Leak Detection" OFF)
if(WITH_VLD AND MSVC)
message("Enabling Visual Leak Detector")
find_library(VLD vld
HINTS "c:/Program Files (x86)/Visual Leak Detector/lib/Win32" "c:/Program Files/Visual Leak Detector/lib/Win32")
find_file(VLD_H vld.h
HINTS "c:/Program Files (x86)/Visual Leak Detector/include" "c:/Program Files/Visual Leak Detector/include")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FIwinsock2.h")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \"/FI${VLD_H}\"")
get_filename_component(VLD_LIBRARY_DIR "${VLD}" PATH)
"""
A python keyring backend that uses 'git-credential-cache'
To enable, edit '~/.local/share/python_keyring/keyringrc.cfg':
[backend]
default-keyring=cachekeyring.CacheKeyring
keyring-path=/path/to/dir
To enable use with mercurial, edit ~/.hgrc:
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}