Skip to content

Instantly share code, notes, and snippets.

@mckamey
mckamey / StringUtils.js
Created July 30, 2010 16:00
.NET-style String.Format implementation for JavaScript
/*global JSON */
if ("undefined" === typeof String.format) {
// String.format: populates a format string with an ordered list of values
/*string*/ String.format = function(/*params*/) {
var args = arguments,
num = args.length,
str = args[0];
@mckamey
mckamey / Foo.MyZebraList.jbst
Created August 14, 2010 16:02
Pygments lexer support for JBST syntax
<%@ Control Name="Foo.MyZebraList" Language="JavaScript" %>
<script type="text/javascript">
/* private members ------------------------------------------ */
/*int*/ function digits(/*int*/ n) {
return (n < 10) ? '0' + n : n;
}
@mckamey
mckamey / EcmaScript.NET-debugger.patch
Created August 23, 2010 15:55
Port of Rhino fix for bug 386997
Index: Projects/EcmaScript.NET/Debugging/DebugFrame.cs
===================================================================
--- Projects/EcmaScript.NET/Debugging/DebugFrame.cs (revision 56306)
+++ Projects/EcmaScript.NET/Debugging/DebugFrame.cs (working copy)
@@ -58,5 +58,11 @@
/// exception object if about to throw exception
/// </param>
void OnExit (Context cx, bool byThrow, object resultOrException);
+
+ /// <summary>
{
"issue" : [
{
"@priority" : "1",
"@type" : "Task",
"@state" : "Fixed",
"@subsystem" : "No subsystem",
"@id" : "DCVR-1",
"@fixedVersion" : "",
"@projectShortName" : "DCVR",
@mckamey
mckamey / doctype.js
Created January 10, 2011 16:57
DocType extraction snippet
function getDocType(document) {
var node = document.firstChild;
while (node) {
var nodeType = node.nodeType;
if (nodeType === 10) {
// doctype
var doctype = '<!DOCTYPE '+(document.documentElement.tagName || 'html').toLowerCase();
if (node.publicId) {
doctype += ' PUBLIC "' + node.publicId + '"';
}
@mckamey
mckamey / LICENSE.txt
Created May 18, 2011 22:17 — forked from 140bytes/LICENSE.txt
Fibonacci
Copyright (c) 2011 Stephen M. McKamey, http://mck.me
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@mckamey
mckamey / LICENSE.txt
Created May 19, 2011 21:51 — forked from 140bytes/LICENSE.txt
Named string formatting
Copyright (c) 2011 Stephen M. McKamey, http://mck.me
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@mckamey
mckamey / datetest.js
Created October 5, 2011 17:20
ECMAScript Date range unit test
try{
module("ES5 ranges");
test("ES5 Epoch", function() {
// epoch
var expected = 0;
var actual = new Date(expected);
@mckamey
mckamey / perf.js
Created October 27, 2011 00:24
Simple JS Perf Timer API
/**
* perf.js
* Simple JS Timer API
*
* @public
* @param {number} alpha weight for EWMA trends (default: 0.2)
* @this {Perf}
* @constructor
*/
var Perf = function(alpha) {