Skip to content

Instantly share code, notes, and snippets.

View pallas's full-sized avatar

Derrick Lyndon Pallas pallas

View GitHub Profile
@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 / 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 / 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 ;;
#!/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 / 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)
@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 / 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>