Skip to content

Instantly share code, notes, and snippets.

View clausd's full-sized avatar

Claus Dahl clausd

View GitHub Profile
@clausd
clausd / gist:7267304
Created November 1, 2013 15:42
The Interval - a Library of Babel
def text_to_number(text, n=1000)
'0.' + text[0..n].unpack('C*').map{ |i| "%02d" % i}.join('')
end
@clausd
clausd / fifo.rb
Created September 2, 2013 19:28
Nonblocking writes, blocking reads
`mkfifo fifotest`
Process.fork do
puts "We're going to write a message to a process who will pick it up later"
nonblocking = open('fifotest', 'w+')
nonblocking.puts "A message for you, Rudy\r\n"
nonblocking.flush
nonblocking.close
puts "Done writing"
end
@clausd
clausd / printmycode.pl
Last active December 15, 2015 12:18
Selfreproducing perl program
$program = <<'EOP';
$program = <<'EOC';
EXPANDME
EOC
$program = substr($program,0,-1);
$outer = $program;
$outer =~ s/EOC(..)$/EOP$1/m;
$outer =~ s/EOC$/EOP/m;
$outer =~ s/EXPANDME/$program/;
print $outer;
@clausd
clausd / gist:2370833
Created April 12, 2012 20:39
Find the line corresponding to a single projected point in Processing (P3D assumed)
/*
Find the 3D coordinates at depth z that project onto planar coordinates (x,y).
Screen position is at z-1 in the screen coordinate system, so z should be less than -1
(basically inverse for screenX/screenY)
*/
PVector screenToDepth(float x, float y, float z) {
// first get the transforms in place
PMatrix3D M = (PMatrix3D) g.getMatrix();
PMatrix3D P = (PMatrix3D) ((PGraphics3D) g).getProjection();
P.apply(M);
@clausd
clausd / x
Created March 10, 2009 18:33
/* Convert selection to HTML entitites - danish chars only */
CmdUtils.CreateCommand({
name: "entitize",
icon: "http://www.classy.dk/favicon.ico",
homepage: "http://www.classy.dk/",
author: { name: "Claus Dahl", email: "dee@classy.dk"},
license: "GPL",
description: "Translates danish characters to html entities",
help: "select text and apply to replace with entitized text",