Skip to content

Instantly share code, notes, and snippets.

View indexzero's full-sized avatar
🗽
✊ Fist in the air in the land of hypocrisy

Charlie Robbins indexzero

🗽
✊ Fist in the air in the land of hypocrisy
View GitHub Profile
function thatYouWantToExport() {
};
if (typeof exports === 'undefined') {
window.myFn = thatYouWantToExport;
} else {
exports.myFn = thatYouWantToExport;
}
@tmpvar
tmpvar / node-require.js-diff_match_patch.js
Created May 25, 2011 03:20
use diff match patch in node and in the browser via require.js
/**
* Diff Match and Patch
*
* Copyright 2006 Google Inc.
* http://code.google.com/p/google-diff-match-patch/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@samsonjs
samsonjs / rate-limiting-queue.js
Created May 25, 2011 06:47
Basic rate limiting queue for node
//// Usage
var queue = createMessageQueue({ messagesPerMinute: 60 })
queue.on('message', function(msg) {
console.log('message: ' + JSON.stringify(msg, null, 2))
})
queue.enqueue({ to: 'avian', from: 'sjs', body: 'cool story bro' })
@tmpvar
tmpvar / level3.md
Created May 26, 2011 22:05 — forked from lloyd/level3.md

This perhaps deserves a blog post, but whatever.

The challenge: What if you wanted to determine what level my Bulgarian language skills were at? Using this sample document:

{
    "name": {
        "first": "Lloyd",
        "last": "Hilaiel"
    },

"favoriteColor": "yellow",

/*
TODO: allow for interpolation!
Requirements:
* local pendingPatches
* tick interval
* send queue to server
* concat queue to transmittedPatches
* revert function([patch, patch])
@jvduf
jvduf / javascript_tricks.js
Last active September 26, 2015 00:38
Misc Javascript Tricks
// The arguments variable in a function is not a real Array. So to be able to
// slice and dice it you need to convert OR handle it as an array:
// 1) Creating a new Array:
[].slice.call(arguments).doWhatEver // slower
// 2) Getting the Array Prototype:
Array.prototype.slice.call(arguments).doWhatEver // faster
// To test something is an Array or not:
var isArray = ({}).toString.call([]);
// But why not? ([]).toString
/**
* Parse the given header `str` into
* an object containing the mapped fields.
*
* @param {String} str
* @return {Object}
* @api private
*/
function parseHeader(str) {
@rwaldron
rwaldron / array.extensions.md
Last active May 4, 2022 13:46
Array.from and Array.of
@dominictarr
dominictarr / example.sh
Created July 11, 2011 11:34
setup git deploy
ssh user@remote
mkdir prod
cd prod
git init
git config receive.denyCurrentBranch false
echo 'cd ~/prod ; git reset --hard' > .git/hooks/post-receive
#maybe also add a command to .git/hooks/post-receive to restart your server?
#forever restart 0
@dominictarr
dominictarr / proposal.markdown
Created July 18, 2011 06:05
middleware system for node-http-proxy

#middleware system for node-http-proxy

##feature requests:

  • 69: easy url proxying. forward x.com/whatever to y.com
  • 66: monitor requests. (use connect middleware - once http-proxy supports it)
  • 60: spin up nodes on request (seems like a bad idea, incoming middleware)
  • 18: gzip responses (would need response middleware)
  • 58: modify responses (would need response middleware)