Skip to content

Instantly share code, notes, and snippets.

@aprell
aprell / floatdump.jl
Created February 8, 2014 17:54
Functions for inspecting IEEE 754 floating-point numbers in Julia
function floatdump(n::Float32)
sign = bits(n)[1]
exp = bits(n)[2:9]
mant = bits(n)[10:end]
println("Sign: $sign $(sign == '1' ? "(-)" : "(+)")")
println("Exponent: $exp ($(parseint(exp, 2) - 127) + 127)")
println("Mantissa: $mant ($(parseint(mant, 2) / 2^23) * 2^23)")
end
function floatdump(n::Float64)
@aprell
aprell / eps2pdf.sh
Created February 10, 2014 18:40
Convert all EPS files in a directory to PDF
#!/usr/bin/env bash
case "$1" in
"-h" | "--help")
echo "Usage: eps2pdf [directory]"
echo ""
echo "Convert all EPS files in a specified directory to PDF."
echo "If no directory is specified, assume the current working directory."
echo ""
exit 0
@aprell
aprell / O1.s
Created March 5, 2014 18:50
Examples of successful tail call optimization in C
.file "tco.c"
.text
.globl fib_tailrec_
.type fib_tailrec_, @function
fib_tailrec_:
.LFB21:
.cfi_startproc
movl %edi, %eax
testl %edi, %edi
je .L7
@aprell
aprell / printf.sh
Created March 21, 2014 15:54
Log file names constructed with printf
foo_bar_$(printf "%03d" $i).log
@aprell
aprell / insert.sh
Created March 21, 2014 16:00
Reminder to learn sed someday...
sed -i "1i Extra line inserted" file.txt
@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; }
@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 / 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 / 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 / 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