Skip to content

Instantly share code, notes, and snippets.

@KayEss
KayEss / console-reporter.js
Last active December 14, 2015 20:09
Components for testing AngularJS controllers and some templates from the command line, using PhantomJS and over the file:// protocol so there's no need to run a web server for build bots etc.
(function() {
if (! jasmine) {
throw new Exception("jasmine library does not exist in global namespace!");
}
var ConsoleReporter = function() {
this.started = false;
this.finished = false;
};
@KayEss
KayEss / skype.json
Created October 18, 2013 12:39
mkschroot configuration file for running Skype inside a schroot.
{
"root": "/var/chroot/",
"source": "http://th.archive.ubuntu.com/ubuntu/",
"http-proxy": "http://apt-cacher:3142/",
"defaults": {},
"schroot": {
"skype": {
"release": "lucid",
"packages": [
"libasound2", "libqt4-dbus", "libqt4-network", "libqt4-webkit",
@KayEss
KayEss / logparser.py
Created January 4, 2014 12:40
Some Python code for parsing the output of the `svn log` command.
#!/usr/bin/env python
import os
import subprocess
import sys
REPO="file:///var/backups/fsl-svn/felspar/"
def capture(args):
@KayEss
KayEss / snake.cpp
Created May 22, 2015 07:13
Brute force solution for Vietnamese snake problem
// Compile as C++14
// clang++ --std=c++14 snake.cpp -O3 -o /tmp/snake && /tmp/snake
// http://www.theguardian.com/science/alexs-adventures-in-numberland/2015/may/20/can-you-do-the-maths-puzzle-for-vietnamese-eight-year-olds-that-has-stumped-parents-and-teachers
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::size_t tries = 0, wins = 0;
@KayEss
KayEss / syscall.cpp
Last active August 29, 2015 14:27
General form for Linux system call
// Signal handling.... sigh
template<typename F> inline
int syscall(F f) {
int result{};
do {
result = f();
} while ( result == -1 && errno == EINTR );
return result;
}
@KayEss
KayEss / check.cpp
Last active August 29, 2015 05:42
`DEBUG` and release builds -- is it reasonable to expect the compiler to completely optimise away the `check` function on non-`DEBUG` builds, but leave the side effects of the arguments alone?
#ifdef DEBUG
inline void check(const auto &b) {
if ( !b ) std::terminate();
}
#else
inline void check(const auto &) {
}
#endif
@KayEss
KayEss / pi.cpp
Last active March 5, 2017 06:12
Estimate pi using monte-carlo method varying radius and number of samples.
// Compile with:
// clang++ --std=c++14 -O3 -o pi pi.cpp
#include <algorithm>
#include <cmath>
#include <experimental/iterator>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <type_traits>
@KayEss
KayEss / coro3.cpp
Last active June 17, 2017 04:18
Coroutine generator
/*
* A generator. Initial code taken from N4649 p15
* http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4649.pdf
*/
#include <experimental/coroutine>
#include <iostream>
@KayEss
KayEss / lisp.cpp
Last active June 9, 2023 17:06
Build me a LISP
/// # Build me a LISP
// Read this nicely formatted at https://kirit.com/Build%20me%20a%20LISP
/**
Normally programming language blog posts get started with grammars and syntax
and parsing and all sorts of stuff like that. I can't be bothered with all of
that, so instead, let's start with the (maybe more interesting aspect) of the
actual evaluation of the code. Here we'll build an evaluation engine for LISP
like languages in less than 50 lines of C++ -- [and literate C++ at
@KayEss
KayEss / urandom.cpp
Last active February 21, 2019 10:55
Check for 32 byte collisions in urandom output
/**
# Look for 32 byte collisions from urandom.
Compile with:
```
clang++ urandom.cpp -std=c++17 -O3 -o urandom -Werror
```
*/