Skip to content

Instantly share code, notes, and snippets.

View willeccles's full-sized avatar
🖤
probably out driving

Will Eccles willeccles

🖤
probably out driving
View GitHub Profile
@willeccles
willeccles / __cplusplus values.md
Last active March 25, 2024 23:38
__cplusplus values for each C++ standard version

__cplusplus Values

Since it's impossible to find one concise source anywhere, as far as I can tell:

ISO C++ Standard Value
1998/2003 199711L
2011 201103L
2014 201402L
2017 201703L
@willeccles
willeccles / build-linaro-macos.sh
Last active March 4, 2024 14:14
Build the Linaro arm-linux-gnueaibhf-gcc toolchain on macOS.
#! /bin/bash
# source for most of this information: https://stackoverflow.com/a/58852167/2712525
set -e
error() {
echo "failed!"
exit 1
}
@willeccles
willeccles / alfred-kitty.scpt
Last active February 26, 2024 11:47
AppleScript for using Kitty in Alfred. This was made for bash, but can easily be made to work with any shell.
(* 2019-06-07: Added nohup and output redirection to fix a bug with "Open Terminal here" feature.
Thanks to @fools-mate for bringing the issue to my attention. *)
on alfred_script(q)
do shell script "cd ~; nohup /Applications/kitty.app/Contents/MacOS/kitty /bin/bash -c \"source ~/.bashrc && " & q & ";/bin/bash\" > /dev/null 2>&1 &"
end alfred_script
@willeccles
willeccles / sockets.h
Last active February 6, 2024 22:52
Cross-platform socket header for both POSIX sockets and Winsock
/*
* File: sockets.h
* Author: Will Eccles
* Date: 2020-03-12
*
* 1. Description
*
* This header attempts to make it easy to use sockets across platforms,
* for both Windows and POSIX systems. While Winsock is often somewhat
* compatible with Berkeley sockets, it is not strictly compatible,
/* Compile with -DUSE_READLINE and -lreadline to use readline for input. */
#include <arpa/inet.h>
#include <errno.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#ifndef ONE_OF_H
#define ONE_OF_H
#include <tuple>
#include <utility>
template <class... T>
struct one_of {
std::tuple<T...> t;
constexpr one_of(T&&... values) : t{std::forward<T>(values)...} {}
@willeccles
willeccles / jedcrc.c
Created October 4, 2021 15:19
Calculate the checksum of the transmission data in a JEDEC .jed file.
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define STX 0x02
#define ETX 0x03
int main(int argc, char** argv) {
FILE* src = NULL;
@willeccles
willeccles / KahanSum.h
Created March 16, 2023 14:04
C++ Kahan summation utility class
// TODO concepts/constraints/SFINAE to keep T as FP
// TODO make this more robust than the very basics
template <class T>
class KahanSum {
public:
KahanSum() : sum_{}, err_{} {}
KahanSum(T init) : sum_{init}, err_{} {}
constexpr KahanSum& Add(T val) {
@willeccles
willeccles / shellandc.c
Last active February 24, 2023 01:52
A C program which is also a valid bash script, and vice versa.
#include <stdio.h>
#define $x ,x
#define $i ,i
#define eval int
#define read scanf
#define $scanfpat "%d", &
#define $(x) ,(x)
#define $open (
#define $close )
#define do {
@willeccles
willeccles / regmap.cpp
Created March 3, 2022 15:41
C++ register mapping
/*
* Basic register map implementation in C++. Makes reading/writing registers
* safer, should be just as efficient as doing things the old fashioned way.
* The setup is a little ugly, but such is life. It was never going to be pretty
* anyway.
*
* Requires C++20, though that could be changed with a little SFINAE trickery.
*
* Example code uses GPIO peripherals on an AM3358.
*