View regions.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local module = {} | |
function module.circle(cx, cy, radius) | |
return function(x, y) return (x - cx)^2 + (y - cy)^2 < radius^2 end | |
end | |
function module.halfspace(rise, run, x0, y0) | |
return function(x, y) return run*(y - y0) < rise*(x - x0) end | |
end |
View scope_exit.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename Func> struct scope_exit | |
{ | |
Func cleanup; | |
scope_exit(Func &&f) : cleanup(std::forward<Func>(f)) {} | |
~scope_exit() { cleanup(); } | |
}; | |
template <typename Func> scope_exit<Func> make_scope_exit(Func &&f) | |
{ |
View require.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdexcept> | |
struct require_error : std::runtime_error { | |
using std::runtime_error::runtime_error; | |
}; | |
void require(bool b, char const *message) { | |
if (!b) { | |
throw require_error(message); | |
} |
View main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function distanceTransform(roomName) { | |
let vis = new RoomVisual(roomName); | |
let topDownPass = new PathFinder.CostMatrix(); | |
for (let y = 0; y < 50; ++y) { | |
for (let x = 0; x < 50; ++x) { | |
if (Game.map.getTerrainAt(x, y, roomName) == 'wall') { | |
topDownPass.set(x, y, 0); | |
} | |
else { |
View demangle.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cxxabi.h> | |
#include <cstdlib> | |
#include <cstddef> | |
#include <iostream> | |
#include <memory> | |
struct clib_free { | |
template<typename T> |
View music.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# based on http://blog.robertelder.org/bash-one-liner-compose-music/ | |
# with overflow, channels, timing, etc. bugs fixed | |
< /dev/urandom hexdump -v -e '/1 "%u\n"' | | |
gawk 'BEGIN { split("0,2,4,5,7,9,11,12",a,",")} | |
{ for (i = 0; i < 0.3125; i += 0.0000625) | |
printf("%02X\n", 100*sin(1382*exp((a[$1 % 8]/12)*log(2))*i)) }' | | |
sed -e 's/.*\(..\)$/\1/g' | | |
xxd -r -p | | |
sox -traw -c 1 -r16000 -b8 -e signed-integer - -tcoreaudio |
View fenv.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <system_error> | |
#include <cfenv> | |
#include <cassert> | |
namespace fe { | |
enum class rounding_mode : int { | |
downward = FE_DOWNWARD, | |
to_nearest = FE_TONEAREST, | |
toward_zero = FE_TOWARDZERO, |
View foil_optimizer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void escape(void *p) { | |
asm volatile("" : : "g"(p) : "memory"); | |
} | |
static void clobber() { | |
asm volatile("" : : : "memory"); | |
} |
View seed_sequence.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
unsigned find_following_seed(unsigned seed) { | |
srand(seed); | |
(void)rand(); | |
int arr[] = {rand(), rand(), rand(), rand()}; | |
for (long long next_seed = 0; next_seed <= UINT_MAX; ++next_seed) { | |
srand(next_seed); |
View find_sequence_length.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main() { | |
srand(1); | |
int arr[] = {rand(), rand(), rand(), rand()}; | |
long long n = sizeof(arr) / sizeof(*arr); | |
while (true) { | |
if (rand() != arr[0]) n += 1; | |
else if (rand() != arr[1]) n += 2; |
NewerOlder