Skip to content

Instantly share code, notes, and snippets.

@aprell
aprell / array.awk
Created February 23, 2015 19:43
Array subscripts are always strings, so beware of uninitialized variables!
#!/usr/bin/awk -f
# For every non-comment, non-blank line
!/(^#)|(^\s*$)/ {
# n is initially zero, which is "" in a string context!
numbers[n] = $0
n++
}
END {
@aprell
aprell / nothing.lua
Created February 21, 2015 15:17
Subtle difference between returning nothing and returning nil in Lua
local function f() end
local function g() return end
local function h() return nil end
-- select can be used to count the number of returned values
print(select("#", f())) -- 0
print(select("#", g())) -- 0
print(select("#", h())) -- 1
-- Note the extra parentheses around the call to force exactly one result (nil)
@aprell
aprell / fib.c
Created February 18, 2015 19:19
Tasking macros after preprocessing
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "tasking.h"
#include "async.h"
int fib(int);
TASK_DECL(int, fib, int n, n);
@aprell
aprell / fib.c
Created February 18, 2015 19:14
CILK_FAKE_* macros after preprocessing
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "cilk_fake.h"
int fib(int);
void fib_spawn_helper(__cilkrts_stack_frame *sf, int *x, int n)
{
CILK_FAKE_SPAWN_HELPER_PROLOG(*sf);
@aprell
aprell / a.lua
Created July 23, 2014 18:18
Determine if file is required by another file
require "b"
@aprell
aprell / fixfox.sh
Created July 14, 2014 10:08
"It looks like you haven't started Firefox in a while."
touch $HOME/.mozilla/firefox/*.default/.parentlock
@aprell
aprell / sort.awk
Created May 27, 2014 10:34
Sorting an array in AWK
#!/usr/bin/awk -f
BEGIN {
i = 0
}
{
numbers[i++] = $1
}
@aprell
aprell / cilk.c
Last active August 29, 2015 14:01
Examples of implicit barriers in OpenMP and Cilk Plus
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <cilk/cilk.h>
int A[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int main(void)
{
int i;
@aprell
aprell / cmacro.patch
Created April 22, 2014 20:23
Building cmacro
diff --git a/Makefile b/Makefile
index 98a7141..a20738b 100644
--- a/Makefile
+++ b/Makefile
@@ -43,7 +43,13 @@ buildapp: $(BUILD)/buildapp ;
$(BUILD)/.reqs:
@echo "Downloading requirements"
- $(LISP_QL) --eval '(ql:quickload :$(NAME))' --quit
+ $(LISP_QL) --eval '(ql:quickload :$(NAME))' \
@aprell
aprell / quine.c
Created March 25, 2014 18:39
A simple quine in C
char *q = "char *q = %c%s%c; int main(void) { printf(q, 34, q, 34); return 0; }"; int main(void) { printf(q, 34, q, 34); return 0; }