Skip to content

Instantly share code, notes, and snippets.

@vicmortelmans
vicmortelmans / gist:1453419
Created December 9, 2011 21:39
XSLT to turn YQL Open Table "csv" output with <row>s and <col>s into semantically structured XML based on title row
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<rows>
<xsl:apply-templates select="//row"/>
</rows>
</xsl:template>
@vicmortelmans
vicmortelmans / gist:1393077
Created November 25, 2011 08:54
TEA encryption
// use (16 chars of) 'password' to encrypt 'plaintext'
function encrypt(plaintext, password) {
var v = new Array(2), k = new Array(4), s = "", i;
plaintext = escape(plaintext); // use escape() so only have single-byte chars to encode
// build key directly from 1st 16 chars of password
for (var i=0; i<4; i++) k[i] = Str4ToLong(password.slice(i*4,(i+1)*4));
function escape(t)
{
var r='';
for(var i=0;i<t.length;i++){
var c=t.charCodeAt(i);
var t1=Math.floor(c/16);
var t2=c%16;
if (t1<10) t1+=48;
else t1+=55;
if (t2<10) t2+=48;
@vicmortelmans
vicmortelmans / txt2optionhtml.pl
Created June 24, 2011 10:29
Perl script that transforms a list of strings into an HTML select element
#!/usr/bin/perl
use HTML::Entities;
print "<select>\n";
while (<STDIN>) {
chop;
$s = encode_entities($_);
print "<option value=\"$s\">$s</option>\n";
}
print "</select>\n";
@vicmortelmans
vicmortelmans / flatten.xslt
Created January 28, 2011 15:04
templates for flattening a purely hierarchical XML structure
<!-- templates for flattening a purely hierarchical XML structure
into a list of <item> records -->
<xsl:template match="*" mode="flatten">
<xsl:apply-templates mode="flatten"/>
</xsl:template>
<xsl:template match="*[not(*)]" mode="flatten">
<!-- working upwards starting from leaf nodes -->
<item>
@vicmortelmans
vicmortelmans / gist:798257
Created January 27, 2011 08:53
XML data + XSL stylesheet for browser + CSS in single file (useful for DMS publishing), including vertical table headers with wrapped text as bonus
<?xml-stylesheet type="text/xsl" href="#"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- the main concept of this file is obtained from
http://stackoverflow.com/questions/360628/embed-xsl-into-an-xml-file -->
<xsl:output omit-xml-declaration="yes"/>
<xsl:key name="reviewers" match="reviewer" use="."/>
<!-- browsers have XSLT 1.0, so 'for-each-group' must be implemented