Skip to content

Instantly share code, notes, and snippets.

@aaronryank
aaronryank / c-lambda.bash
Last active December 8, 2021 09:10
Convert a C function to a lambda via executable strings.
#!/usr/bin/env bash
read -p "Function return type: " val
if [ "$1" != "mini" ]; then
read -p "Function name: " name
fi
read -p "Function argument list: " list
echo "$val $name($list) {" >f.c
echo "Enter code:"
#include <stdlib.h>
#include "include/string.h"
const char *errlist[] = {
"no error (operation succeeded", /* 0 */
"not owner", /* EPERM */
"no such file or directory", /* ENOENT */
"no such process", /* ESRCH */
"interrupted system call", /* EINTR */
"I/O error", /* EIO */

Subtract and branch if less than or equal to zero (SUBLEQ)

Subtract the contents of address a from the contents of address b, store the result in address b, and if the result is non-positive, transfer control to address c. If the result is positive, execution continues to the next instruction in the code. So subleq a, b, c would be equivalent to:

mem[b] -= mem[a];
if (mem[b] <= 0)
    goto c;

A variant of subleq is subneg, which is equivalent to subleq except instead of mem[b] <= 0 it performs mem[b] < 0.

@aaronryank
aaronryank / rk.pl
Last active February 28, 2018 01:46
INCOMPLETE RK TO C COMPILER - usage: perl rk.pl < input.rk > output.c
use Text::ParseWords;
print "typedef void *UNTYPED;\n";
print "#define ARGS UNTYPED args[]\n";
print "#define INT __uint128_t\n";
print "#define STR char *\n\n";
my @variables;
my $variable_count = 0;
my @code;
@aaronryank
aaronryank / ppcg-answers-integers.txt
Last active January 15, 2018 21:59
Frequency of languages in my PPCG answers
1 ;#
1 ABAP
1 ACL2
1 A Pear Tree
1 ASM
1 Awk
1 Babel
1 BaCon
1 Bob
1 Ceylon
@aaronryank
aaronryank / operations.bit
Last active December 28, 2017 19:14
arithmetic via bitwise operations
COMMENT add $1 and $2 into $3
.ADD:
LABEL &1
AND $1 $2 *1
XOR $1 $2 $1
SL *1 &1 $2
JMP @1 $2
RET $1
COMMENT increment $1 into $2
@aaronryank
aaronryank / oeis.bash
Last active December 21, 2017 01:47
Downloads all OEIS sequence lists and formats them into C arrays
#!/usr/bin/env bash
# Downloads all OEIS sequence lists and formats them into C arrays
for i in `seq 1 296700`; do
printf -v s "A%.6d" $i
echo $s >/dev/stderr
echo -n "long long int $s[] = {"
wget -qO- https://oeis.org/$s/list | tr -d '\n' | sed 's/^.*<pre>/<pre>/' | cut -c 7- | cut -f1 -d"]" | tr -d '\n'
echo "};"
done
@aaronryank
aaronryank / setup.bash
Last active December 8, 2017 03:16
Set up a new PC/workstation: wget -qO- https://xf-technologies.github.io/setup | xargs wget
#!/usr/bin/env bash
# test internet connection
wget -q --spider http://google.com
if [ ! $? -eq 0 ]; then
echo "No internet connection, exiting..."
exit $?
fi
@aaronryank
aaronryank / quine.exe
Last active December 7, 2017 04:08
Windows Executable error quine
The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.