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
/* macro.h */ | |
#define GREATEST_ASSERT_EQm(MSG, EXP, GOT) \ | |
do { \ | |
greatest_info.msg = MSG; \ | |
greatest_info.fail_file = __FILE__; \ | |
greatest_info.fail_line = __LINE__; \ | |
if ((EXP) != (GOT)) { \ | |
GREATEST_CALL_TEARDOWN(); \ | |
return -1; \ | |
} \ |
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
#define CONTRIVED_IF_EXAMPLE(F, COUNTER) F(COUNTER); COUNTER++; | |
if (some_condition) CONTRIVED_IF_EXAMPLE(func, x); | |
/* This will expand to: */ | |
if (some_condition) func(x); x++; | |
/* Note that the `x++;` statement will always evaluate - it is outside the `if`. Defining the macro with braces will fix the issue. */ | |
#define FIXED_IF_EXAMPLE(F, COUNTER) { F(COUNTER); COUNTER++; } | |
/* Similarly, compare */ | |
#define CONTRIVED_EXAMPLE(X, Y) X + Y |
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 test_basic_encoding_for_known_case() | |
local ints = {1, 0, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4} | |
local res = rle.encode(ints) | |
local expected = {1, 0, 0, 0, 6, 2, 3, 3, 3, 4} | |
for i=1,#expected do | |
assert_equal(expected[i], res[i]) | |
end | |
end |
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
-- Generate a random array of bytes, with some redundancy (via sorting). | |
function gen_int_array(limit) | |
limit = limit or 10000 | |
local ri = lunatest.random_int | |
local length = ri(1, limit) | |
local ints = {} | |
for i=1,length do | |
-- keep them small, to increase duplication | |
ints[i] = ri(0, 2^8 - 1) | |
end |
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 test_encoding_and_decoding_should_be_lossless() | |
assert_random({ name="encode_decode", | |
always={ -- regressions: always test these seeds | |
-- found test_encoding_N_zeroes's edge case | |
3735485075354, 2721442120304, 3956609256407, | |
-- found test_encoding_two_zeroes's edge case | |
175063139413, 3771894109384, 1972533966070}, | |
}, | |
function () | |
local ints = gen_int_array() |
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
-- Use literal zero for escape before compression data | |
local esc = 0 | |
-- Run-length-encode an array of ints. | |
function encode(ints) | |
local res, i, ct = {}, 1, 1 -- result, index, count | |
while i <= #ints do | |
local v = ints[i] | |
while ints[i+1] == v do | |
ct = ct + 1 |
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 test_encoding_two_zeroes() | |
-- this should be {0, 2, 0}, not {0, 0, 0, 0}, to keep | |
-- encoding from filling up with too many escapes. | |
local ints = {0, 0} | |
local res = rle.encode(ints) | |
local expected = {0, 2, 0} | |
for i=1,#expected do | |
assert_equal(expected[i], res[i]) | |
end |
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 <sys/mman.h> | |
#include <err.h> | |
int main(int argc, char **argv) { | |
char *slab = NULL, *after = NULL, *overlap = NULL; | |
int sz = 4096; | |
#define CHECK(P) if (P == NULL) err(1, #P); | |
slab = mmap(NULL, sz, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON,-1,0); | |
CHECK(slab); |
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
def this_is_okay | |
{ | |
:a => "b" | |
} | |
end | |
def this_is_too | |
yield ({ | |
:a => "b" | |
}) |
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
#!/bin/sh | |
VOICE="-v fred" | |
#VOICE="-v ralph" | |
#VOICE="-v lee" | |
curl http://rapbot.jit.su/ 2>/dev/null | awk ' | |
{ | |
for (i=1; i<NF; i++) { | |
if (match($i, "twitter.com/share")) { |
OlderNewer