Skip to content

Instantly share code, notes, and snippets.

Brandon Hsiao brhsiao

Block or report user

Report or block brhsiao

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@brhsiao
brhsiao / defer.hpp
Created Apr 18, 2019
create a child process, pass it stdin, read its stdout
View defer.hpp
#pragma once
#include <utility>
template <typename F>
struct Defer {
Defer(F f) : f(f) {}
~Defer() { f(); }
F f;
};
@brhsiao
brhsiao / defer.hpp
Created Feb 24, 2019
C++ defer macro
View defer.hpp
#include <utility>
template <typename F>
struct Defer {
Defer(F f) : f(f) {}
~Defer() { f(); }
F f;
};
template <typename F>
View for.c
#define uniq2(a, b) a ## b
#define uniq(a) uniq2(a, __LINE__)
#define For(arr, n) \
auto uniq(xs) = arr; \
u32 uniq(i) = 0; \
u32 uniq(len) = n; \
for (auto it = uniq(xs)[uniq(i)]; (uniq(i) < uniq(len)) && (it = uniq(xs)[uniq(i)], true); uniq(i)++)
// USAGE:
@brhsiao
brhsiao / booleangame.coffee
Last active Feb 2, 2019
script for booleangame.com
View booleangame.coffee
# script for https://booleangame.com/
colors = ['Yellow', 'Green', 'Purple']
run = ->
stack = []
opers = []
push2 = (it) ->
if typeof(it) is 'number' || colors.includes(it)
View wolfram.js
const rule = parseInt(process.argv[2], 10)
const rules = Array(8).fill(0).map((_, i) => (rule >> i) & 1)
let s = new Array(process.stdout.columns).fill(0)
s[Math.floor(s.length / 2)] = 1
setInterval(() => {
console.log(s.map(x => x === 1 ? '' : ' ').join(''))
s = s.map((x, i) => rules[(4 * (s[i-1] || 0)) + (2*x) + (1 * (s[i+1] || 0))]);
}, 100)
You can’t perform that action at this time.