Skip to content

Instantly share code, notes, and snippets.

View cjsmeele's full-sized avatar
🐪
​🦋🐧

Chris Smeele cjsmeele

🐪
​🦋🐧
View GitHub Profile
@cjsmeele
cjsmeele / test.hh
Last active May 10, 2016 20:55
Miniscule C unit testing framework
/**
* \file
* \brief Miniscule unit testing framework.
* \author Chris Smeele
*/
#pragma once
/* Copyright (c) 2016 Chris Smeele
*
* Permission is hereby granted, free of charge, to any person
#!/bin/sh
pkill -x xcape
# Begin met een standaard US layout als basis.
setxkbmap us
# - Snelle toegang tot accenten etc. in level3 via rechter Alt.
# - Compose toets voor alle andere combinaties.
# - Ik ben vergeten waarom ik de laatste in de lijst heb en wat die doet.
@cjsmeele
cjsmeele / better_python3
Last active October 26, 2021 11:52
better_python3
#!/usr/bin/env perl
# This adds the post-inc, post-dec, pre-inc and pre-dec operators to python!
# Additionally, it supports the -O3 optimization feature.
my $optimized = 0;
if (@ARGV and $ARGV[0] eq '-O3') {
shift;
@cjsmeele
cjsmeele / hwlib-glcd-oled-spi.hpp
Last active October 9, 2016 19:00
SPI glcd oled driver for hwlib
/**
* \file hwlib-glcd-oled-spi.hpp
* \brief SPI OLED driver for 128x64 screens.
* \author Chris Smeele
* \copyright Copyright (c) 2016, Chris Smeele
* \date 2016-10-06
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@cjsmeele
cjsmeele / hwlib-due-spi.hpp
Created October 9, 2016 18:57
Native SPI support for Arduino Due in hwlib
/**
* \file
* \brief Due / sam3x8e native SPI.
* \author Chris Smeele
* \date 2016-10-09
* \copyright Copyright (c) 2016, Chris Smeele
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@cjsmeele
cjsmeele / attach-gdb.pl
Created July 24, 2017 12:39
Attach GDB to a spawned program matching a certain name within ~100ms
#!/usr/bin/env perl
use 5.12.0;
use warnings;
my $pname = $ARGV[0] // die "usage: $0 NAME\n";
for (my $i = 0;; ++$i) {
state @pids;
chomp(my @new_pids = `pgrep $pname`);
@cjsmeele
cjsmeele / match.hh
Created November 13, 2017 00:35
C++-ish sort-of switch statement reimplementation.
/**
* \file
* \brief C++-ish sort-of switch statement reimplementation.
* \author Chris Smeele
*
* Copyright (c) 2017, Chris Smeele
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@cjsmeele
cjsmeele / generator.scm
Created November 27, 2017 12:50
Scheme generator macro
(define-macro generator
(lambda (params . body)
(let ((cont (gensym "gen-cont"))
(yieldc (gensym "gen-yield")))
`(lambda ,params
(let ((,cont #f))
;; cont will point to the last yield call.
(lambda ()
(let/cc ,yieldc
;; yieldc returns from the generator.
#define die(...) \
do { \
fprintf(stderr, "[error] %s:%d: ", __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
exit(1); \
} while (0)
#define printd(...) \
do { \
@cjsmeele
cjsmeele / fizzbuzz.cc
Last active March 14, 2018 09:05
MPL Fizzbuzz
#include <mpl/mpl.hpp>
using namespace kvasir::mpl;
struct fizz{};
struct buzz{};
struct fizzbuzz{};
template<typename C = identity>
using fizzbuzzed = make_int_sequence<