This file contains hidden or 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
#!/bin/bash | |
if [[ $# -lt 2 ]]; then | |
echo "Usage: $0 <depfile> <command...>" >&2 | |
exit 1 | |
fi | |
# The .d file we're going to write. | |
DEPSFILE=$1 | |
shift |
This file contains hidden or 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
# Copyright Andy Chu | |
class switch(object): | |
"""A ContextManager that translates to a C switch statement.""" | |
def __init__(self, value): | |
# type: (int) -> None | |
self.value = value | |
def __enter__(self): | |
# type: () -> switch |
This file contains hidden or 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
#!/usr/bin/env python3 | |
# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) | |
import shlex | |
import subprocess | |
import sys | |
import textwrap | |
def with_pty(command): |
This file contains hidden or 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
#!/bin/sh | |
# Likely originally by Carl Shapiro | |
sort | | |
uniq -c | | |
sort -n | | |
sed 's/^ *//' | | |
awk 'BEGIN { OFS="\t"} { sum += $1; print sum, $1, substr($0, 1 + index($0, " ")) }' | | |
sort -n -r | | |
awk 'BEGIN { IFS=OFS="\t"; print "cum", "pct", "freq" }$1 > max { max = $1 }{ print int($1/max*100), int($2/max*100), $2, $3 }' |
This file contains hidden or 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
/* | |
Type-safe enum class bitmasks. | |
Based on work by Andre Haupt from his blog at | |
http://blog.bitwigglers.org/using-enum-classes-as-type-safe-bitmasks/ | |
To enable enum classes to be used as bitmasks, use the ENABLE_BITMASK_OPERATORS | |
macro: | |
enum class MyBitmask { | |
None = 0b0000, | |
One = 0b0001, | |
Two = 0b0010, |
This file contains hidden or 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
// Need Clang 13 for __attribute__((musttail)) | |
// clang++-13 -std=c++11 -g -O0 stencil.cpp | |
#include <cassert> | |
#include <cstdint> | |
#include <cstdio> | |
#include <cstring> | |
#include <vector> | |
#include <sys/mman.h> |
This file contains hidden or 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
(() => { | |
//////////////////////////////////////////////////////////////////////////////// | |
// Dragging | |
const dragTarget = document.getElementById('dragTarget'); | |
const uploadFiles = document.getElementById('uploadFiles'); | |
const loadExample = document.getElementById('loadExample'); | |
let dragging = 0; | |
let filesInput; |
This file contains hidden or 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
// | |
// Simple stack-based virtual machine tests. | |
// | |
// I use two slightly different strategies to manage the | |
// interpreter stack: First is using the "naive" approach | |
// of keeping a stack pointer that is bumped/decremented | |
// for every instruction that has stack operands. The second | |
// approach uses a "stack cache" register to cache the | |
// Top-of-Stack (TOS) value. | |
// |
This file contains hidden or 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 <stdbool.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
// TODO(max): Consider writing this in Rust or Nim for some extra reader | |
// appeal. | |
typedef enum { | |
kInt, |
This file contains hidden or 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
import sys | |
def compile(prog): | |
result = ( | |
"#include <stdbool.h>\n" | |
"#include <stdio.h>\n" | |
"#include <string.h>\n" | |
"int execute() {\n" | |
"int acc = 0;\n" |