Skip to content

Instantly share code, notes, and snippets.

View MaxBarraclough's full-sized avatar

Max Barraclough MaxBarraclough

View GitHub Profile
@MaxBarraclough
MaxBarraclough / asciimatics_button_bug_demo.py
Created January 5, 2021 14:57
asciimatics_button_bug_demo.py
#!/usr/bin/env python3
## This simple application demonstrates a bug in
## the mouse-click handling for buttons, in asciimatics:
## mouse-clicks on the right side of buttons, fail to register.
## It seems especially evident in buttons with short label strings.
## Dependency:
## pip install asciimatics
@MaxBarraclough
MaxBarraclough / cpp_type_safe_lib_demo.cpp
Last active November 15, 2020 23:23
Demo of the type_safe C++ library
// A small toy program to explore some of what we can do with the
// 'type_safe' library: https://github.com/foonathan/type_safe/
// We will see that we can use it to create distinct new integer types,
// capable of ordinary arithmetic, and *without* implicit conversions.
//
// We will use this to implement Ada-style strong typing, protecting
// against confusing a NumApples_type value with a NumPennies_type value.
//
@MaxBarraclough
MaxBarraclough / boost_strong_typedef_demo.cpp
Last active November 15, 2020 19:59
BOOST_STRONG_TYPEDEF Demo
// A small toy program (in fact it does nothing at all)
// to explore what we can do with BOOST_STRONG_TYPEDEF.
// We will see that it creates a distinct new type, with permissive
// implicit conversions regarding the original type.
//
// BOOST_STRONG_TYPEDEF has its uses, but we will see that we can't use
// BOOST_STRONG_TYPEDEF to implement Ada-style strong typing, such as to protect
// against confusing a NumApples_type value with a NumPennies_type value.
@MaxBarraclough
MaxBarraclough / hello.adb
Created November 8, 2020 15:14
Print an uninitialized integer in Ada
-- Prints a nondeterministic integer value
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
subtype NumFingers is Integer range 0..10;
my_num_fingers : NumFingers; -- := 4;
begin
@MaxBarraclough
MaxBarraclough / amazon_lambda_start_tagged.py
Last active May 10, 2020 22:31
Amazon Lambda script: start all appropriately tagged instances
## Amazon Lambda script: start all appropriately tagged instances
##
## Runs in Amazon Lambda as Python 2.7 or as Python 3.6.
## Intended to be invoked on a schedule by Amazon Cloud Watch.
## Tag relevant instances with label 'autostart', value 'true'.
## TODO It could be good to add logging to this script
@MaxBarraclough
MaxBarraclough / regexOddness.cs
Last active May 19, 2017 17:10
Unexpected different behaviour when using parentheses in C# regex
System.Text.RegularExpressions.Regex separatorRegex1
= new System.Text.RegularExpressions.Regex("a");
System.Text.RegularExpressions.Regex separatorRegex2
= new System.Text.RegularExpressions.Regex("(a)");
string str = "a";
string[] split1 = separatorRegex1.Split(str); // { "", "" }
string[] split2 = separatorRegex2.Split(str); // { "", "a", "" }