Skip to content

Instantly share code, notes, and snippets.

@peterbraden
peterbraden / JQuery Highlighter .js
Created February 16, 2011 19:18
Highlight words in html with a jquery plugin using jquery methods rather than raw DOM.
/*
* HTML Highlighter
*/
(function($){
$.fn.highlight = function(words, options){
var elements = $(this)
, settings = {
className: 'highlight'
, caseSensitive: false
}
@peterbraden
peterbraden / Local ISO String for Date
Created December 23, 2010 00:40
toISOString with timezone support
Date.prototype.toLocalISOString = function(){
// ISO 8601
var d = this
, pad = function (n){return n<10 ? '0'+n : n}
, tz = d.getTimezoneOffset() //mins
, tzs = (tz>0?"-":"+") + pad(parseInt(tz/60))
if (tz%60 != 0)
tzs += pad(tz%60)
@peterbraden
peterbraden / optparse.js
Created December 1, 2010 20:52
Option Parsing for node.js scripts
/*
* returns [{opts}, [args]]
*/
var optParse = function(argv){
var opts = {}
, args = []
for(var i in argv){
var x = argv[i]
if (x[0] == '-'){
It would be nice to have a browser native delay function that added
a function to the call stack to be run immediately, but not blocking
UI, similar to
> setTimeout(func, 0).
Currently prototype does this - prototype.function.defer sets a
timeout of 0.01.
In my experience though, setting a timeout has a delay - Resig's