Skip to content

Instantly share code, notes, and snippets.

View insin's full-sized avatar
⚠️
Cannot read property 'status' of undefined

Jonny Buchanan insin

⚠️
Cannot read property 'status' of undefined
View GitHub Profile
@insin
insin / RegExp-findall.js
Created April 8, 2011 11:12
findAll method for RegExps with results in the vein of Python's re.findall
RegExp.prototype.findAll = function(str) {
var match = null, results = [];
while ((match = this.exec(str)) !== null) {
switch (match.length) {
case 1:
results[results.length] = match[0];
break;
case 2:
results[results.length] = match[1];
break;
@insin
insin / dom_template.js
Created May 6, 2011 12:07
Leading-vs-trailing commas with a speculative DOM template API
// Which of these would you rather play hunt-the-missing-comma with?
$template({name: 'article_list', extends: 'article_base'},
$block('content',
DIV({'class': 'articles'},
$for('article in articles',
DIV({id: 'article{{ article.id }}'},
H2('{{ article.title }}'),
DIV({'class': 'body'},
$html('{{ article.body }}')
@insin
insin / DOMBuilder-Template.WIP.js
Created May 19, 2011 07:04
Exploratory WIP against a speculative API for DOMBuilder Templates
function Variable(name) {
this.name = name;
}
function VariableNotFoundError(name, context) {
this.name = name;
this.context = context;
}
function Context() {
@insin
insin / gist:1031662
Created June 17, 2011 15:38
Boilerplate for serving a regular old HTML table as application/vnd.ms-excel, apropos acheiving Excel surround sound
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT">
<meta http-equiv=Content-Type content="text/html; charset=UTF-8">
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
@insin
insin / index.html
Last active February 8, 2024 15:14
Export a <table> to Excel - http://bl.ocks.org/insin/1031969
<!DOCTYPE html>
<html>
<head>
<title>tableToExcel Demo</title>
<script src="tableToExcel.js"></script>
</head>
<body>
<h1>tableToExcel Demo</h1>
<p>Exporting the W3C Example Table</p>
@insin
insin / modified.js
Created June 22, 2011 20:13
Object vs. function singleton
var loader = (function() {
var index = 0
, timeout = null
, symbols = ['└', '├', '┌', '┬', '┐', '┤', '┘', '┴'];
function show () {
console.log(symbols[index]);
index = (index + 1) % symbols.length;
timeout = setTimeout(show, 200);
}
@insin
insin / sillySingleton.js
Created June 22, 2011 21:25
sillySingleton
// Please... just don't
var S = (function() {
var instance = null
function S() {
if (instance !== null) return instance
if (!(this instanceof S)) return new S()
instance = this
}
@insin
insin / metametametameta.js
Created July 10, 2011 03:11
Yo dawg, I heard you like call() and apply()...
// Call apply() in the context of document.getElementById with the arguments: document, ['header']
Function.prototype.apply.call(document.getElementById, document, ['header'])
// Apply apply() in the context of document.getElementById with the arguments: document, ['header']
Function.prototype.apply.apply(document.getElementById, [document, ['header']))
// Call call() in the context of document.getElementById with the arguments: document, header
Function.prototype.call.call(document.getElementById, document, 'header')
// Apply call() in the context of document.getElementById with the arguments: document, header
@insin
insin / gist:1154287
Created August 18, 2011 15:16
Utility Block from Sacrum
!function(__global__, server) {
// =============================================================== Utilities ===
var DOMBuilder = (server ? require('DOMBuilder') : __global__.DOMBuilder)
, forms = (server ? require('newforms') : __global__.forms)
var slice = Array.prototype.slice
, toString = Object.prototype.toString
@insin
insin / gist:1155505
Created August 18, 2011 23:08
Sacrum demo commands
git clone git://github.com/insin/sacrum.git
cd sacrum
npm install -d
node server.js
Go to http://127.0.0.1:8000/admin/
Click around (notice JavaScript logging in your browser's console)
Disable JavaScript