Skip to content

Instantly share code, notes, and snippets.

function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {
@whump
whump / yapcna2013.md
Last active December 14, 2015 23:49
Perl and Backbone.js

Perl meets Modern Web UI

Web Frameworks for the client such as Backbone, Knockout, and Angular have changed how we build web applications1. Rendering's on the client2 now. How do you take advantage of that? Do you want to take advantage of that?

In this talk I'll walk you through an example web application that sends a skeletal UI over the wire to the browser, then builds grid and detail views using JavaScript, out of data returned over a API implemented in Perl.


  1. Except that WebVan was doing this back in 2001.
@whump
whump / xmlSerialzing.js
Last active December 14, 2015 14:59
You need to return XML to an API. Unfortunately IE8 and older is still inconsistent with how modern browsers handle XML document creation. You still don't want to create XML by concatenating strings, but you have jQuery.
// Assuming that you have JQuery and Underscore in your global namespace
// you have an array of strings you want to convert to an XML document
function toXML(data) { // data = ['string'(, ...)]
var s = '', $xml;
// build an empty structure
// <items><item/><item/>...</items>
// yes, this is string concatenation,
// but we control the vocabulary
_(this.length).times(function() { s = s + '<item/>'; });
s = '<items>' + s + '</items>';
@whump
whump / bootstrapping.md
Last active December 12, 2015 00:08
A quick note on bootstrapping Backbone models without XSSing yourself.

Writing out the initial model data as a JSON object in a SCRIPT literal can leave you open to a cross-site scripting/injection attack.

To mitigate against this risk, use the OWASP guideline for bootstrapping an application with JSON data.

Write the HTML-escaped JSON inside of a hidden div, then fetch the contents of the div and parse it using JSON.parse.

<div style="display: none;">
!= $data
</div>
@whump
whump / foo.js
Created August 7, 2012 23:46
A Testing Git
(function foo() {
var a, b;
a = b = 1;
})(window);
@whump
whump / gist:1557694
Created January 4, 2012 00:07 — forked from pete/gist:57898
Experiments in revision control: Curry recipe.
My personal recipe for Japanese curry, which has mutated over the years and is
now open-source thanks to github, hot damn. Some of the ingredients are not
very Japanese, but curry came to Japan from England which got it from India to
begin with, so whatever.
1.5 - 2 lbs. of meat, prefer thin-sliced beef (komagire), pork works, too.
Thin-sliced stuff is always best, but in a pinch stewing beef works. Bacon
works surprisingly well. Chicken will work, technically, but if you must,
@whump
whump / gist:1557693
Created January 4, 2012 00:07 — forked from pete/gist:57898
Experiments in revision control: Curry recipe.
My personal recipe for Japanese curry, which has mutated over the years and is
now open-source thanks to github, hot damn. Some of the ingredients are not
very Japanese, but curry came to Japan from England which got it from India to
begin with, so whatever.
1.5 - 2 lbs. of meat, prefer thin-sliced beef (komagire), pork works, too.
Thin-sliced stuff is always best, but in a pinch stewing beef works. Bacon
works surprisingly well. Chicken will work, technically, but if you must,