Skip to content

Instantly share code, notes, and snippets.

@josher19
josher19 / vm_node.js
Created May 16, 2012 06:26
Simple shallow copy of global will not work as expected with runInNewContext
function clone(obj) { var nobj={}, key; for(key in obj) nobj[key]=obj[key]; return nobj; }
var local = null
var g = clone(global);
local = 3
console.assert(local === 3, 'not initialized to 3')
console.assert(null == g.local, 'g.local should be null or undefined')
@josher19
josher19 / yql-geocoder.html
Created April 20, 2012 09:40
Use Google and YQL to geocode addresses
<!DOCTYPE html>
<html>
<head>
<title>Geocode TSV</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
</head>
<body>
<form>
<textarea rows=10 cols=80 name=inp id=inp >
Post_author,post_date,post_date_gmt,post_title,category,IMAGE,tags,post_content,post_excerpt,post_status,comment_status,ping_status,post_password,post_name,to_ping,pinged,post_modified,post_modified_gmt,post_content_filtered,post_parent,menu_order,post_type,post_mime_type,comment_count,geo_address,geo_latitude,geo_longitude,map_view,add_feature,timing,contact,email,twitter,facebook,proprty_feature,post_city_id,video,is_featured,paid_amount,alive_days,paymentmethod,remote_ip,ip_status,pkg_id,featured_type,total_amount,website,comments_data,rating_data
@josher19
josher19 / runLimitedQueue.coffee
Created April 20, 2012 09:39
Example run of a LimitedQueue
LimitedQ = require './LimitedQueue'
assert = require 'assert'
lq = new LimitedQ(3)
lq2 = new LimitedQ()
lq.addListener "alldone", ->
console.log "alldone", arguments
lq.addListener "done", ->
@josher19
josher19 / LimitedQueue.coffee
Created April 20, 2012 09:38
Limited Queue based on suggestions from http://stereopsis.com/async/
# On user event -> push event into a n-element queue.
# If the number of outstanding requests is <n, fire request immediately.
# When an outstanding request works or fails, fire a pending queued request if one is waiting.
EventEmitter = process.EventEmitter or require?('events').EventEmitter or {}
LimitedQueue = (@n = 2, @log = false) ->
@log = console.log if @log is true and console? and console.log
@q = []
@req = []
@josher19
josher19 / livescript.html
Created April 20, 2012 07:30
Run LiveScript Code
<!DOCTYPE html>
<html>
<head>
<title>Run LiveScript Code</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
<script src="https://raw.github.com/gkz/LiveScript/master/extras/livescript.js" async=true ></script>
</head>
<body>
<form>
<textarea rows=10 cols=80 name=inp id=inp >
@josher19
josher19 / jquery.mobile.datebox.i18n.zh-CN.utf8.js
Created March 19, 2012 08:47
Updated Chinese translation of jQuery Mobile datebox plugin
/*
* jQuery Mobile Framework : plugin to provide a date and time picker.
* Copyright (c) JTSage
* CC 3.0 Attribution. May be relicensed without permission/notifcation.
* https://github.com/jtsage/jquery-mobile-datebox
*
* Translation Updated by: Joshua S. Weinstein
*
*/
@josher19
josher19 / JSONDate-interactive.html
Created February 28, 2012 06:35
Interactively test JSONDate on Android Webkit browser
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>JSONDate Tester for Android Phonegap</title>
<script type="text/javascript" charset="utf-8" src="js/phonegap.js"></script>
<script type="text/javascript" charset="utf-8" src="js/sugar-1.2.2.min.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", appReady, false);
@josher19
josher19 / JSONDate.js
Created February 28, 2012 06:09
Convert JSON Dates to Javascript Date Objects for older browsers (including Android Webkit)
JSONDate = (function() {
function isoDate(r, tz) {
// log(arguments);
return fixTimezone(new Date(r[0], r[1] - 1, r[2], r[3], r[4], r[5], r[6] || 0), tz);
}
function noop(it) {
return it;
}
/** Convert quoted printable text to plain text using QP.decode. */
QP = QuotedPrintable = {
decode: function (data) { return unescape(data.replace(/=\r?\n/g, "").replace(/=/g, "%")); }
, encode: function (inp) { return this.sliceup( inp.replace(/[^ a-zA-Z0-9:.,<>'";\r\n!-<>-~]/g, function(c) { return escape(c).replace(/%/g, "=") }) ).replace(/ \r?\n/g, "=20\r\n").replace(/\t\r?\n/g, "=09\r\n"); }
, sliceup: function (chunk, sz, sep) { sz=(sz-0)||75; var i, res=[], len = chunk.length/sz; for(i=0; i<len; ++i) res[i]=chunk.slice(i*sz, (i+1)*sz); return res.join(sep || "=\n"); }
}
@josher19
josher19 / NQ.js
Created February 6, 2012 09:31
Async Limited Queue
var NQ = {
n: 1
,q: []
,add: function add(fn) { this.push(fn); this.next(); return this; }
,push: function push(fn) { this.q.push(fn); return this; }
,fire: function fire() { if (!this.q.length) return "empty"; this.run(this.q[0]);
this.q.shift(); return this.q.length; }
,cancel: function cancel() { this.q.length = 0; }