Skip to content

Instantly share code, notes, and snippets.

@luser-dr00g
luser-dr00g / apl.ps
Last active August 29, 2015 13:57
APL-like calculations in Postscript. Intended to help (me, a human) interpret the J and APL answers to http://codegolf.stackexchange.com/questions/12103/generate-a-universal-binary-function-lookup-table
/i{[1 1 4 3 roll {} for ]}def
%10 i == %[1 2 3 4 5 6 7 8 9 10]
/+{
dup type /arraytype eq { % ? []
1 index type /arraytype eq { % [] []
2 copy length exch length ne {
2 copy length exch length exch lt { exch } if % now nA > nB
2 copy length exch length exch sub % A B nA-nB
[ 3 2 roll % A nA-nB [ B
@luser-dr00g
luser-dr00g / apl2.ps
Last active August 29, 2015 13:57
revision/simplification of apl.ps
%apply unary proc to array. ie. proc implements a monadic operator
/mop{ % A proc
1 index type /arraytype eq {
[ 3 1 roll % [ A proc
exch % [ proc A
{ % [ ... proc A_i
1 index op % [ ... proc A_i'
exch % [ ... A_i' proc
}forall
%1 http://www.ams.org/journals/mcom/1954-08-046/
/init{
P{ %check P for validity
W 1 ne {ERROR:W_p!=1} if
}forall
/Ptab <<
P {
dup
} forall
@luser-dr00g
luser-dr00g / L.c
Last active August 29, 2015 13:57
Lukasiewicz Logic Intepreter in C.
//http://www.ams.org/journals/mcom/1954-08-046/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum { LOW = -10000, HIGH = 10000 };
char *P = "01";
@luser-dr00g
luser-dr00g / labels.pl
Created August 2, 2014 10:11
perl/postscript csv->avery labels
#!/usr/bin/perl
# labels.pl reads csv records in the form:
# "Name","123 Street","Apt","City, ST ZIP"
# from a file named "addr.csv" and
# produces a postscript program on stdout
# suitable for piping into ps2pdf or
# even distiller, maybe
# CAVEATS: prototype produces at most
# one page. label and sheet sizes are hard-coded
# at 3 3-inch-width labels which are 4*17 points
@luser-dr00g
luser-dr00g / stars.ps
Created August 30, 2014 09:30
my god! it's full of stars
/starpath { % n r1 r2 x y
matrix currentmatrix 6 1 roll % [] n r1 r2 x y
translate % [] n r1 r2
10 dict begin {/r2 /r1 /n} {exch def}forall % []
/da 360 n div def
r2 0 moveto
n {
@luser-dr00g
luser-dr00g / xcr.c
Created August 30, 2014 09:35
xcb+cairo hello world window
//xcr.c
//cc -o xcr $(pkg-config --cflags --libs cairo xcb xcb-icccm) xcr.c -lcairo -lxcb -lxcb-icccm
#include <stdlib.h>
#include <string.h>
#include <cairo.h>
#include <cairo-xcb.h>
#include <xcb/xcb.h>
#include <xcb/xcb_image.h>
#include <xcb/xcb_aux.h>
#include <xcb/xcb_icccm.h>
@luser-dr00g
luser-dr00g / font_transform_test.c
Created September 23, 2014 07:55
testing FT_Set_Transform with FT_Render_Glyph and accessing advance vector
//make font_transform_test CFLAGS=`freetype-config --cflags ` LDLIBS=`freetype-config --libs` LDLIBS+=`pkg-config fontconfig --libs` LDLIBS+='-lm'
/*
* Xpost - a Level-2 Postscript interpreter
* Copyright (C) 2013, Michael Joshua Ryan
* Copyright (C) 2013, Vincent Torri
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@luser-dr00g
luser-dr00g / shapes.ps
Created September 23, 2014 11:51
A few small drawing functions: polygons, spirals, and stars.
%polygon.ps
%rad n {proc} atpoly -
%call proc having rotated+scaled
%so (1,0) is each vertex of rad-radius n-polygon
/atpoly {
%3 args (atpoly)=
4 dict begin /p exch def /n exch def % rad
/m matrix currentmatrix def
%(rad2=)print rad2 =
%dup (atpoly: rad=)print =
#include<ctype.h>
#include<stdint.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/stat.h>
#include<unistd.h>
typedef intptr_t I; typedef uintptr_t U;
typedef short S; typedef unsigned short US;
typedef signed char C; typedef unsigned char UC;