Skip to content

Instantly share code, notes, and snippets.

Avatar

Derrick Lyndon Pallas pallas

View GitHub Profile
@pallas
pallas / snake_to_camel.c
Created Oct 25, 2020
in-place conversion of string from snake case to camel case
View snake_to_camel.c
// SPDX-License-Identifier: Unlicense
// Author: Derrick Lyndon Pallas <derrick@pallas.us>
#include <stdbool.h>
#include <ctype.h>
char *
snake_to_camel(char * string) {
bool upper = true;
char * camel = string;
@pallas
pallas / welford.h
Created Oct 19, 2020
Calculate mean, variance, deviation, & error using Welford's algorithm
View welford.h
// SPDX-License-Identifier: MIT
// Author: Derrick Lyndon Pallas <derrick@pallas.us>
#include <cmath>
template <typename T = double>
class welford {
public:
welford() : _count(0), _mean(T(0.0)), _squared_distance(T(0.0)) { }
@pallas
pallas / kiosk.sh
Last active Oct 15, 2020
Raspberry Pi screensaver (feedback) + Pandora (pianobar) + AirPlay (rpiplay) kiosk
View kiosk.sh
#!/bin/bash
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <derrick@pallas.us>
#
# /etc/rc.local: xinit /usr/lib/kiosk.sh &
#
# http://rss-glx.sourceforge.net/
# https://github.com/PromyLOPh/pianobar
# https://github.com/FD-/RPiPlay
@pallas
pallas / tmux.conf
Last active Aug 21, 2020
tmux.conf
View tmux.conf
unbind C-b
set -g prefix C-a
bind-key a send-prefix
bind-key C-c new-window
bind-key C-a last-window
bind-key C-n next-window
bind-key C-p previous-window
bind-key C-d detach-client
setw -g aggressive-resize on
@pallas
pallas / aprs.sh
Last active Oct 29, 2020
RTL-SDR -> DIREWOLF -> APRS
View aprs.sh
#!/bin/bash
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <derrick@pallas.us>
for arg in "$@"; do
shift
case "$arg" in
# default = 144.390M
--iss|--ariss|--aprsat) FREQUENCY=145.825M ;;
--nz|--newzealand) FREQUENCY=144.575M ;;
@pallas
pallas / spring-cleaning.sh
Last active Jul 15, 2020
Spring clean memory on Linux systems
View spring-cleaning.sh
#!/bin/bash
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <derrick@pallas.us>
sync &&
echo 3 > /proc/sys/vm/drop_caches &&
echo 1 > /proc/sys/vm/compact_memory &&
true
#
@pallas
pallas / git-me.sh
Last active Jul 15, 2020
git-me: show how the local repo differs from the upstream tracking branch
View git-me.sh
#!/bin/sh
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <derrick@pallas.us>
exec git log --oneline "$@" @{u}..
#
@pallas
pallas / fancy_debug.h
Created Aug 28, 2019
Simple but powerful debugging primitive
View fancy_debug.h
// SPDX-License-Identifier: Unlicense
bool global_debug = false;
#define DEBUG(format, ...) do { \
if (global_debug) \
fprintf(stderr, "%s:%d %s " format "\n", __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__); \
} while(false)
@pallas
pallas / mac_to_ipv6network.py
Created Aug 9, 2019
Inject MAC address into IPv6 Network
View mac_to_ipv6network.py
# SPDX-License-Identifier: Unlicense
from ipaddress import IPv6Network
from binascii import unhexlify
network = IPv6Network("2001:DB8::/32")
mac = "12:34:56:78:9a:bc"
mac_bytes = b''.join(map(unhexlify, mac.split(':')))
address = network[int.from_bytes(mac_bytes, byteorder='big')]
print(network, mac, mac_bytes, address)
View dblock-update.sh
#!/bin/bash
# Author: Derrick Pallas
# License: zlib
BASE='dblock-set'
TEMP=${BASE}$$
ipset create -exist "$BASE" hash:ip --netmask 24 || exit 1
iptables -nL INPUT | grep -q "$BASE" ||
(
( iptables -N "$BASE" || iptables -F "$BASE" ) &&