169 lines
2.1 KiB
Lua
169 lines
2.1 KiB
Lua
local M = {}
|
|
|
|
local snippet = {
|
|
[[
|
|
#include <stdio.h>
|
|
int main(void)
|
|
{
|
|
long x = 470020878965;
|
|
puts((void *)&x);
|
|
return 0;
|
|
}
|
|
]],
|
|
[[
|
|
float Q_rsqrt(float number)
|
|
{
|
|
long i;
|
|
float x2, y;
|
|
const float threehalfs = 1.5F;
|
|
x2 = number * 0.5F;
|
|
y = number;
|
|
i = *(long *)&y;
|
|
i = 0x5f3759df - (i >> 1);
|
|
y = *(float *)&i;
|
|
y = y * (threehalfs - (x2 * y * y));
|
|
return y;
|
|
}
|
|
]],
|
|
[[
|
|
#include <stdio.h>
|
|
int main(int argc, char **argv)
|
|
{
|
|
return printf("%s: Comma operator\n", argv[0]), 2;
|
|
}
|
|
]],
|
|
[[
|
|
void welford(double x, double *n, double *mean, double *m2)
|
|
{
|
|
(*n)++;
|
|
double d = x - *mean;
|
|
*mean += d / *n;
|
|
*m2 += d * (x - *mean);
|
|
}
|
|
]],
|
|
[[
|
|
#define ever (;;)
|
|
for ever {
|
|
;
|
|
}
|
|
]],
|
|
[[
|
|
void *xmalloc(size_t size)
|
|
{
|
|
void *r = malloc(size);
|
|
if (!r)
|
|
abort();
|
|
return r;
|
|
}
|
|
]],
|
|
[[
|
|
#include <stdint.h>
|
|
uint32_t rotl32(uint32_t x, uint32_t n)
|
|
{
|
|
return (x << n) | (x >> (32 - n));
|
|
}
|
|
]],
|
|
[[
|
|
#include <stddef.h>
|
|
void memzero(void *p, size_t n)
|
|
{
|
|
unsigned char *t = p;
|
|
while (n--)
|
|
*t++ = 0;
|
|
}
|
|
]],
|
|
[[
|
|
#include <stdio.h>
|
|
int main(void)
|
|
{
|
|
int a = 0;
|
|
if (a++ == 0 && a++ == 1 && a++ == 2)
|
|
printf("chain ok\n");
|
|
return 0;
|
|
}
|
|
]],
|
|
[[
|
|
static unsigned long next = 1;
|
|
int lrand(void)
|
|
{
|
|
next = next * 1103515245 + 12345;
|
|
return (unsigned)(next / 65536) & 32767;
|
|
}
|
|
]],
|
|
|
|
[[
|
|
#!/bin/sh
|
|
set -eu
|
|
printf '%s\n' "$1"
|
|
]],
|
|
[[
|
|
#!/bin/sh
|
|
if [ "$#" -eq 0 ]; then
|
|
exit 1
|
|
fi
|
|
printf '%s\n' "$@"
|
|
]],
|
|
[[
|
|
#!/bin/sh
|
|
x=0
|
|
while :; do
|
|
x=$((x + 1))
|
|
[ "$x" -gt 3 ] && break
|
|
done
|
|
printf '%s\n' "$x"
|
|
]],
|
|
[[
|
|
#!/bin/sh
|
|
exec 3>&1
|
|
printf 'ok\n' >&3
|
|
]],
|
|
[[
|
|
#!/bin/sh
|
|
f() {
|
|
printf '%s\n' "$1"
|
|
}
|
|
f "${1:-none}"
|
|
]],
|
|
[[
|
|
#!/bin/sh
|
|
for i in a b c; do
|
|
printf '%s\n' "$i"
|
|
done
|
|
]],
|
|
[[
|
|
#!/bin/sh
|
|
x=$(printf '%s' foo)
|
|
printf '%s\n' "$x"
|
|
]],
|
|
[[
|
|
#!/bin/sh
|
|
read x
|
|
printf '%s\n' "$x"
|
|
]],
|
|
[[
|
|
#!/bin/sh
|
|
PATH=/bin:/usr/bin
|
|
export PATH
|
|
printf '%s\n' "$PATH"
|
|
]],
|
|
[[
|
|
#!/bin/sh
|
|
trap 'printf trap\n' HUP INT TERM
|
|
sleep 1
|
|
]]
|
|
}
|
|
|
|
M.daily_random = function()
|
|
local t = os.date("*t")
|
|
local seed = t.day + t.month * 31 + t.year * 997
|
|
local a = 1103515245
|
|
local c = 12345
|
|
local m = 2 ^ 31
|
|
seed = (a * seed + c) % m
|
|
local r = seed / m
|
|
local n = #snippet
|
|
return snippet[math.floor(r * n) + 1]
|
|
end
|
|
|
|
return M
|