Skip to content

Instantly share code, notes, and snippets.

View yocontra's full-sized avatar

contra yocontra

View GitHub Profile
@yocontra
yocontra / gulp.coffee
Last active April 3, 2017 02:43
Ideal build system
gulp = require 'gulp'
clean = require 'gulp-clean'
jade = require 'gulp-jade'
coffee = require 'gulp-coffee'
minify = require 'gulp-minify'
###
quick syntax ideas:
gulp.files() takes a glob and is an array of file streams
@yocontra
yocontra / idiotFilter.coffee
Created July 1, 2013 22:44
Filters idiots and business people from using your web page
module.exports = (req, res, next) ->
ua = req.get 'user-agent'
return next() if !ua or /[cC]hrome\/([\d\w\.\-]+)/i.test ua
res.redirect "https://www.google.com/intl/en/chrome/browser/beta.html"
res.end()
@yocontra
yocontra / redis-loader.js
Created May 28, 2013 18:09
Loads a JSON object into redis - good for testing. Supports flat keys as well as nested values
var redis = require('redis');
var async = require('async');
module.exports = loadRedis;
function loadRedis(opts, cb) {
var errored = false;
var client = redis.createClient(opts.redis.port, opts.redis.host);
client.once('error', function (e) {
@yocontra
yocontra / imgLoader.coffee
Created May 20, 2013 21:48
External image loader for chrome apps
# Just pass in the parent of the image tags.
# Image tags should have a .external-img class and data-src should be the external url
define ->
cache = {}
loader = ($el) ->
lazyLoad = (img) ->
el = $ img
url = el.attr 'data-src'
orm = require 'orm'
async = require 'async'
fs = require 'fs'
{join} = require 'path'
modelDir = "./models"
modelDir = join __dirname, modelDir
module.exports =
create: (cb) ->

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')
  ;
@yocontra
yocontra / faces.js
Created March 27, 2013 06:38
faces json output script
JSON.stringify($("img").map(function () {
var e = $(this);
return {
url: e.parent().attr('href'),
image: e.attr('src')
};
}).get());
[][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]][([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]]+([][[]]+[])[+[[+!+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[+!+[]]]]+([][[]]+[])[+[[+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[
@yocontra
yocontra / djb2.jl
Created February 26, 2013 15:48
djb2 hashing in julia
function djb2(s)
r = 5381
for i in s
c = int(i)
r = r + (r << 5) + c
end
return r
end
println(djb2("test"))
@yocontra
yocontra / server.js
Last active December 14, 2015 05:29
Streaming mongodb APIs
var mongoose = require('mongoose');
var http = require('http');
var JSONStream = require('JSONStream');
var PersonSchema = new mongoose.Schema({
name: String,
num: Number
});
mongoose.connect("mongodb://localhost:27017");