Skip to content

Instantly share code, notes, and snippets.

View gerardpaapu's full-sized avatar
🏠
Working from home

Gerard Paapu gerardpaapu

🏠
Working from home
View GitHub Profile
#lang scheme
(provide Take)
(define (Take source . patterns)
(if (= (length patterns) 1)
(Take1 source (first patterns))
(map (lambda (source)
(apply Take source (rest patterns)))
(Take1 source (first patterns)))))
var maxX = 0, minX = Infinity;
images.each(function(item){
var imageCoords = item.getCoordinates(seatingPlan);
maxX = Math.max(maxX, imageCoords.right);
minX = Math.min(minX, imageCoords.left);
});
var dimensions = {'left': minX, 'right': maxX};
////////////////////////////////////////////////////////////////////
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="32" height="32" style="position: absolute; left: 77px; top: 40px; ">
<desc>Created with Rapha&#xC3;&#xAB;l</desc>
<defs/>
<path fill="#333333" stroke="none" d="{paste the path string here}"/>
<rect x="0.5" y="0.5" width="32" height="32" r="0" rx="0" ry="0" fill="#000000" stroke="#000" style="opacity: 0; " opacity="0"/>
</svg>
function getContainerDimensions(elements, container){
// Returns an object { top: ..., right: ..., bottom: ..., left: ... }
// so that the dimensions will cover all of `elements`
//
// `container` is the element that the dimensions are relative to
return Seq.from(elements)
.invoke('getDimensions', container)
.pluck('top', 'right', 'bottom', 'left')
.unzip().apply(function (tops, rights, bottoms, lefts){
var parsedate = function (str) {
// parsedate: String -> Date or null
//
// Decodes the timestamps from the ihackernews api, it seems like
// they're produced by the following proc from news.arc.
//
// (def text-age (a)
// (tostring
// (if (>= a 1440) (pr (plural (trunc (/ a 1440)) "day") " ago")
// (>= a 60) (pr (plural (trunc (/ a 60)) "hour") " ago")
@gerardpaapu
gerardpaapu / sets.js
Created March 23, 2011 22:32
Sets represented as javascript functions, with an Object Oriented(tm) interface
var Set = function (test) {
this.test = test;
};
Set.prototype = {
'add': function(s) {
return Set.add(this, s);
},
'complement': function () {
return Set.complement(this);
@gerardpaapu
gerardpaapu / gradients.rkt
Created July 20, 2011 01:54
A mini servlet to serve svg gradients
#lang racket
(require xml
net/url
web-server/servlet
web-server/servlet-env)
(define (svg-response svg)
(make-response/full
200 #"OK"
(current-seconds) #"image/svg+xml; charset=utf-8"
@gerardpaapu
gerardpaapu / Function.getMetadata.js
Created August 16, 2011 23:58
Function.getMetadata
(function () {
// Reading Function Metadata
// =========================
//
// !!!!! DO NOT USE ANY OF THIS CODE FOR ANY PURPOSE IT WILL EAT YOU KIDS
//
// Because `Function.prototype.toString()` returns something like
// function source-code, we can parse it for metadata like the names of
// the formal arguments or the name of the function.
//
@gerardpaapu
gerardpaapu / fps.js
Created August 19, 2011 05:09
FPS counter for every javascript paradigm I could think of...
// Counting frames per second
// ==========================
//
// My basic strategy is to divide the time taken over the
// last n frames and return n seconds / time seconds.
//
// I must provide a method to say that a frame is done, so that
// the time can be recorded and a method to get the current FPS,
// and I must store the last n + 1 (because of the fencepost
// problem) times.
@gerardpaapu
gerardpaapu / calc.js
Created September 15, 2011 05:56
Calc
// Calc
// ----
//
// A dumb/simple embeddable language for performing simple calculations
// It's so simple that you know it won't throw errors or run forever.
//
// e.g. ($area % 0.96) x 1.05 units 0.96
// $area x 0.05
// (2 x $centreline_length) x (2 x $width)
//