Skip to content

Instantly share code, notes, and snippets.

View pallas's full-sized avatar

Derrick Lyndon Pallas pallas

View GitHub Profile
@pallas
pallas / minkowski_distance.cc
Last active January 12, 2023 16:24
Minkowski distance function
// All rights reserved,
// Derrick Pallas
// License: zlib
#include <cmath>
#include <cstdlib>
#include <limits>
#include <vector>
template <typename fp_type>
@pallas
pallas / intrusive_tree.hh
Last active October 29, 2022 18:26
C++ intrusive red-black tree
// All rights reserved,
// Derrick Pallas
// License: zlib
#ifndef INTRUSIVE_TREE_H
#define INTRUSIVE_TREE_H
#include <cassert>
#include <cstddef>
#include <algorithm>
@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 <derrick@pallas.us>
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 / aprs.sh
Last active October 29, 2020 04:52
RTL-SDR -> DIREWOLF -> APRS
#!/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 / 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 <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 October 19, 2020 18:34
Calculate mean, variance, deviation, & error using Welford's algorithm
// 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 October 15, 2020 00:50
Raspberry Pi screensaver (feedback) + Pandora (pianobar) + AirPlay (rpiplay) kiosk
#!/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 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 / 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 <derrick@pallas.us>
exec git log --oneline "$@" @{u}..
#