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
    
  
  
    
  | // http://paulirish.com/2011/requestanimationframe-for-smart-animating/ | |
| // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating | |
| // requestAnimationFrame polyfill by Erik Möller | |
| // fixes from Paul Irish and Tino Zijdel | |
| (function() { | |
| var lastTime = 0; | |
| var vendors = ['ms', 'moz', 'webkit', 'o']; | |
| for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { | |
| window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; | 
  
    
      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
    
  
  
    
  | // requires raf.js (polyfil) | |
| (function(){ | |
| var ids = {}; | |
| function requestId(){ | |
| var id; | |
| do { | |
| id = Math.floor(Math.random() * 1E9); | |
| } while (id in ids); | 
  
    
      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
    
  
  
    
  | // note: uses the native "mozDash" or "webkitLineDash" functionality if present, polyfills with manual dashed-lines drawing | |
| // note #2: this polyfill does *not* currently work with arcs, bezier-curves, and quadratic-curves. that functionality would be theoretically possible, but is probably very hard to implement. | |
| // note #3: it also doesn't work with rect() or strokeRect() yet, though those should be relatively straightforward to do, by manually drawing the lines using lineTo(). | |
| (function(){ | |
| var _moveTo = CanvasRenderingContext2D.prototype.moveTo, | |
| _lineTo = CanvasRenderingContext2D.prototype.lineTo, | |
| pos = { | 
  
    
      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
    
  
  
    
  | // ********** | |
| // NOTE: this is a stupid trivial example illustrating automatic | |
| // type-coercion, not an example of the kind of data-structure logic | |
| // you'd ever actually use. don't miss the forest for the trees. | |
| // Read down in the comment thread for 'myCoolString' for a slightly | |
| // more sensible example. | |
| // | |
| // NOTE #2: this gist thread was spawned from a twitter discussion | |
| // about `parseInt(0/1,19)==18`: | |
| // https://twitter.com/getify/status/221009838006747136 | 
  
    
      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
    
  
  
    
  | EventEmitter.prototype.either = function(evt,cb) { | |
| var self = this, orAPI = {or: bindHandler}, handlers = {}; | |
| function bindHandler(evt,cb) { | |
| if (!handlers || handlers[evt]) return; | |
| handlers[evt] = function(){ | |
| for (var e in handlers) { | |
| self.removeListener(e,handlers[e]); | |
| } | 
  
    
      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 xhr, form_data = new FormData(); | |
| xhr = new XMLHttpRequest(); | |
| xhr.open("POST","http://barfoo.com/upload"); | |
| xhr.setRequestHeader("Content-Type","multipart/form-data"); | |
| xhr.setRequestHeader("File-Name",file.name); | |
| xhr.setRequestHeader("File-Size",(file.size || file.fileSize)); | |
| xhr.setRequestHeader("File-Type",file.type); | |
| xhr.setRequestHeader("Session-ID",12345); | 
  
    
      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 fs = require("fs"); | |
| var jParser = require("jParser"); | |
| var eof = false; | |
| fs.readFile("sample.jpg",function(err,data) { | |
| if (!err) { | |
| var view = new jDataView(data, undefined, undefined, false); | |
| var parser = new jParser(view,{ | |
| // JPG | 
  
    
      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 fs = require("fs"); | |
| var jParser = require("jParser"); | |
| var eof = false; | |
| fs.readFile("sample.jpg",function(err,data) { | |
| if (!err) { | |
| var view = new jDataView(data, undefined, undefined, false); | |
| var parser = new jParser(view,{ | |
| // JPG | 
  
    
      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
    
  
  
    
  | <!-- here's the PHP'ish way of making inline decisions while constructing HTML markup --> | |
| <select name="foobar"> | |
| <option value="bam" <?=($foobar==="bam"?"selected":"")?>>Bam</option> | |
| <option value="baz" <?=($foobar==="baz"?"selected":"")?>>Baz</option> | |
| </select> | |
| <input type="radio" name="foobar" value="bam" <?=($foobar==="bam"?"checked":"")?>> Bam | |
| <input type="radio" name="foobar" value="baz" <?=($foobar==="baz"?"checked":"")?>> Baz | 
  
    
      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
    
  
  
    
  | // all this `toJSON()` does is filter out any circular refs. all other values/refs, | |
| // it passes through untouched, so it should be totally safe. see the test examples. | |
| // only extend the prototype if `toJSON` isn't yet defined | |
| if (!Object.prototype.toJSON) { | |
| Object.prototype.toJSON = function() { | |
| function findCircularRef(obj) { | |
| for (var i=0; i<refs.length; i++) { | |
| if (refs[i] === obj) return true; | |
| } |