Skip to content

Instantly share code, notes, and snippets.

<!-- this is how you generate unique DOM IDs in XSLT for use in generating HTML -->
<!-- generate the unique ID with "uid-" prefix and assign it to the uid variable -->
<xsl:variable name="uid">
<xsl:value-of select="concat('uid-',generate-id(.))"/>
</xsl:variable>
<!-- now use the unique id to generate a <label>-<select> pair -->
<label for="{$uid}">Menu:</label>
<select id="{$uid}">
<!-- footnote heeds to toggle the corresponding footnote div -->
<xsl:template match="aos:footnote" mode="aos-content"><xsl:variable name="footnoteNumber"><xsl:apply-templates select="." mode="get-footnote-number"/></xsl:variable><sup id="footnote-{$footnoteNumber}-link" class="footnote-link"><a href="#" onclick="revealFootnote('#footnote-{$footnoteNumber}'); return false"><xsl:value-of select="$footnoteNumber"/></a></sup>
</xsl:template>
@zuk
zuk / byte_operations.js
Created March 19, 2010 22:04
How to convert between integers and bytes in JavaScript
// Here's how to do basic integer<->byte (string/char) operations in JavaScript.
// Took me a good while to dig this up.
function intToChar(integer) {
return String.fromCharCode(integer)
}
function charToInt(char) {
return char.charCodeAt(0)
}
@zuk
zuk / restful_blog2.rb
Created March 23, 2010 19:36
Attempt at re-writing Reststop for Camping 2.0
#!/usr/bin/env ruby
require 'rubygems'
require 'ruby-debug'
#gem 'camping', '~> 2.0'
#gem 'reststop', '~> 0.3'
$: << '../../camping-camping/lib'
$: << '../lib'
require 'camping-unabridged'
$(document).ready(function() {
rollcall = new S3.Rollcall('http://proto.encorelab.org:7070')
token = rollcall.getCurrentToken()
rollcall.fetchSessionForToken(token, function(data) {
console.log(data.session.user.username)
console.log(data.session.user.encrypted_password)
// log in to xmpp from here using those credentials
}
}
// uses jquery.url.js --> https://github.com/allmarkedup/jQuery-URL-Parser
var S3 = window.S3 || {}
S3.Rollcall = function(url) {
this.url = url
}
S3.Rollcall.prototype = {
/**
@zuk
zuk / ruby-xmpp-example.rb
Created February 26, 2011 22:16
Ruby XMPP Example
require 'rubygems'
require 'xmpp4r/client'
require 'xmpp4r/roster'
require 'colored'
require 'pp'
include Jabber
Jabber.debug = true
@zuk
zuk / blather-groupchat-example.rb
Created February 27, 2011 22:36
XMPP Groupchat reverse echo using Blather
require 'rubygems'
require 'blather/client'
# CONFIGURATION
jid = 'tester@proto.encorelab.org'
password = "foofoo"
chatroom = "s3@conference.proto.encorelab.org"
setup(jid, password)
@zuk
zuk / rollcall-auth.js
Created September 19, 2011 12:36
Basic rollcall.js authentication example
rollcall = new Rollcall.Client('http://rollcall.aardvar.encorelab.org')
token = rollcall.getCurrentToken()
if (token) {
rollcall.fetchSessionForToken(WallCology.token, function(data) {
session = data.session
// The session hash has the user's account info in it. At this point
// we can assume the user is authenticated.
})
/**
* Let Rollcall take care of asking the user for their login and password.
*/
if ($_REQUEST['token'])
$token = $_REQUEST['token'];
elseif ($_SESSION['token'])
$token = $_SESSION['token'];
else
$token = null;