Skip to content

Instantly share code, notes, and snippets.

View pallas's full-sized avatar

Derrick Lyndon Pallas pallas

View GitHub Profile
@pallas
pallas / CMakeLists.txt
Created August 25, 2022 16:43
Basic CMake template for C library with executables and tests
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <[email protected]>
cmake_minimum_required(VERSION 3.1)
cmake_policy(SET CMP0076 NEW)
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
#!/bin/bash
# Author: Derrick Pallas
# License: zlib
BASE='spamhaus-set'
TEMP=${BASE}$$
ipset create -exist "$BASE" hash:net || exit 1
iptables -w 300 -nL INPUT | grep -q "$BASE" ||
(
( iptables -N "$BASE" || iptables -F "$BASE" ) &&
@pallas
pallas / snake_to_camel.c
Created October 25, 2020 19:08
in-place conversion of string from snake case to camel case
// SPDX-License-Identifier: Unlicense
// Author: Derrick Lyndon Pallas <[email protected]>
#include <stdbool.h>
#include <ctype.h>
char *
snake_to_camel(char * string) {
bool upper = true;
char * camel = string;
@pallas
pallas / welford.h
Created October 19, 2020 18:34
Calculate mean, variance, deviation, & error using Welford's algorithm
// SPDX-License-Identifier: MIT
// Author: Derrick Lyndon Pallas <[email protected]>
#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 October 15, 2020 00:50
Raspberry Pi screensaver (feedback) + Pandora (pianobar) + AirPlay (rpiplay) kiosk
#!/bin/bash
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <[email protected]>
#
# /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 August 21, 2020 22:17
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 October 29, 2020 04:52
RTL-SDR -> DIREWOLF -> APRS
#!/bin/bash
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <[email protected]>
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 July 15, 2020 20:40
Spring clean memory on Linux systems
#!/bin/bash
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <[email protected]>
sync &&
echo 3 > /proc/sys/vm/drop_caches &&
echo 1 > /proc/sys/vm/compact_memory &&
true
#
@pallas
pallas / git-me.sh
Last active July 15, 2020 20:41
git-me: show how the local repo differs from the upstream tracking branch
#!/bin/sh
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <[email protected]>
exec git log --oneline "$@" @{u}..
#
@pallas
pallas / fancy_debug.h
Created August 28, 2019 21:33
Simple but powerful debugging primitive
// 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)