Skip to content

Instantly share code, notes, and snippets.

View yocontra's full-sized avatar

contra yocontra

View GitHub Profile
const os = require('os');
const fs = require('fs');
const path = require('path');
const execFile = require('child_process').execFile;
const tmpfile = path.join(os.tmpdir(), process.versions.v8+'.flags.json');
const exclusions = ['--help'];
module.exports = function (cb) {
fs.exists(tmpfile, function (exists) {
@yocontra
yocontra / polyfill.js
Created August 28, 2013 17:04 — forked from remy/gist:350433
LocalStorage/SessionStorage polyfill
var isStorageAvailable = function (storage) {
if (typeof storage == 'undefined') return false;
try { // hack for safari incognito
storage.setItem("storage", "");
storage.getItem("storage");
storage.removeItem("storage");
return true;
}
catch (err) {
return false;

I'm writing an app that talks to Apple to verifyReceipts. They have both a sandbox and production url that you can post to.

When communicating with Apple, if you receive a 21007 status, it means you were posting to the production url, when you should be posting to the sandbox one.

So I wrote some code to facilitate the retry logic. Here's a simplified version of my code:

var request = require('request')
  , Q = require('q')
  ;
rivets.configure({
adapter: {
subscribe: function(obj, keypath, callback) {
if (obj instanceof Backbone.Collection) {
obj.on('add remove reset', function () {
callback(obj[keypath])
});
} else {
obj.on('change:' + keypath, function (m, v) { callback(v) });
};
@yocontra
yocontra / detectanimation.coffee
Created June 28, 2012 20:17 — forked from lakenen/detectanimation.js
JavaScript animated GIF detection!
isAnimatedGif = (src, cb) ->
request = new XMLHttpRequest()
request.open "GET", src, true
request.responseType = "arraybuffer"
request.addEventListener "load", ->
arr = new Uint8Array request.response
return cb false if arr[0..3] isnt [0x47,0x49,0x46,0x38]
request.send()
require 'should'
http = require 'http'
Vein = require 'vein'
port = Math.floor(Math.random() * 1000) + 8000
server = new Vein http.createServer().listen port
describe 'first test', (done)->
it 'should do stuff', (done)->
server.drop()
server.stack = []
@yocontra
yocontra / rAFshim.coffee
Created February 14, 2012 21:11 — forked from phated/rAFshim.coffee
window.requestAnimationFrame shim
###
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
Coffeescript and AMD by Blaine Bublitz
###