This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LimitedQ = require './LimitedQueue' | |
assert = require 'assert' | |
lq = new LimitedQ(3) | |
lq2 = new LimitedQ() | |
lq.addListener "alldone", -> | |
console.log "alldone", arguments | |
lq.addListener "done", -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Looks like functions defined with `->` work but those defined with `function` do not. | |
answer = 42 | |
deepthought = -> "let me think about it for a while" | |
function question then answer | |
console.assert deepthought! == 'let me think about it for a while' | |
console.log deepthought! | |
console.assert question! == answer | |
console.log question! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repl.defineCommand('search', { | |
help: 'search through repl history', | |
action: function(cmd) { | |
if (this.rli.history) this.outputStream.write(this.rli.history.filter(function(line,n) {return n && -1 !== line.indexOf(cmd)}).reverse().join("\n")+"\n"); | |
this.displayPrompt(); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var esc = function (c) { var x=parseInt(c, 36); return isFinite(x) ? "%" + (x+87).toString(16) : c; } | |
var escw = function(word) { return word.replace(/[a-z]/g, esc); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
"<-!": { | |
"definition": "Suppress returns on backcalls.", | |
"details": "Temporary variable to be assigned in callback on the left and function to call on the right. Returns undefined (void). ", | |
"example": "val <-! $.ajax 'examples/helloworld.roy'\nval2 <-! $.ajax 'examples/alias.roy'\nconsole.log val + val2", | |
"compilesTo": "$.ajax('examples/helloworld.roy', function(val){\n $.ajax('examples/alias.roy', function(val2){\n console.log(val + val2);\n });\n});", | |
"see": [ | |
"!", | |
"<-", | |
"backcall", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
------------------------------------------------------------------------------ | |
isaacRand.js: By Josh Weinstein, based on | |
Rand.java: By Bob Jenkins. My random number generator, ISAAC. | |
rand.init() -- initialize | |
rand.val() -- get a random value | |
MODIFIED: | |
960327: Creation (addition of randinit, really) | |
970719: use context, not global variables, for internal state | |
980224: Translate to Java |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// von n semi-random, but repeats too quickly | |
function nextr(n) { var d=(n*n); if (d%100==0) d /= 100; if (d < 100) d = d*5242870; d=d.toString(); var s=d.length; return d.substring(s-6, s-2)-0 } | |
function nextr(n) { var d=(n*n); if (d%100==0) d /= 100; if (d < 100) d *= 132645290; d=d.toString(); var s=d.length; return d.substring(d.length / 2 - 2, d.length / 2 + 2)-0 } | |
function testn(n,max) { max=max||1000; for(var h={}, i=0; i<max; ++i) { n = nextr(last=n); if(h[n]) break; h[n]=last||true; } return [i,n,last,h]; } | |
// primes |