Skip to content

Instantly share code, notes, and snippets.

@kana
kana / lazy.js
Created April 9, 2013 09:57
Lazy evaluation in JavaScript
function delay(expressionAsFunction) {
var result;
var isEvaluated = false;
return function () {
if (!isEvaluated)
result = expressionAsFunction();
return result;
};
}
@shussekaido
shussekaido / our_setup_script.js
Created December 5, 2012 14:56
MongoDB M102 week6 file
db = db.getSisterDB("config");
var mongosConn = db; // assume we connected to a mongos to get going
var res = null;
function check() {
printjson(res);
if( !res || !res.ok ) {
throw "check(): not ok, stopping";
@jpattishall
jpattishall / TouchTimerWorkaround.js
Last active September 1, 2022 07:58
setTimeout workaround for iPad and iOS6
/**
Workaround for iOS 6 setTimeout bug using requestAnimationFrame to simulate timers during Touch/Gesture-based events
Author: Jack Pattishall (jpattishall@gmail.com)
This code is free to use anywhere (MIT, etc.)
Note: UIWebView does not support requestAnimationFrames. If your timer is failing during a scroll event,
take a look at https://gist.github.com/ronkorving/3755461 for a potential workaround.
Usage: Pass TRUE as the final argument for setTimeout or setInterval.
@kTmnh
kTmnh / ios6-timers.js
Last active April 27, 2022 21:24 — forked from ronkorving/ios6-timers.js
iOS6 webkit timer bug workaround
(function (window) {
// This library re-implements setTimeout, setInterval, clearTimeout, clearInterval for iOS6.
// iOS6 suffers from a bug that kills timers that are created while a page is scrolling.
// This library fixes that problem by recreating timers after scrolling finishes (with interval correction).
// This code is free to use by anyone (MIT, blabla).
// Original Author: rkorving@wizcorp.jp
var timeouts = {};
var intervals = {};
var orgSetTimeout = window.setTimeout;
var orgSetInterval = window.setInterval;
@potix2
potix2 / gist:3339485
Created August 13, 2012 11:01
ApacheBenchでJSONをPOSTする
% ab -n 10 -c 10 -p json.file -T "application/json; charset=utf-8" http://localhost/
Stability ratings: 0-5
0 - Deprecated. This feature is known to be problematic, and changes are
planned. Do not rely on it. Use of the feature may cause warnings. Backwards
compatibility should not be expected.
1 - Experimental. This feature was introduced recently, and may change
or be removed in future versions. Please try it out and provide feedback.
If it addresses a use-case that is important to you, tell the node core team.
@markdaws
markdaws / common.js
Created February 7, 2012 05:18
Example of how to share JavaScript between client and node.js
// common.js ======================================
(function(exports) {
// Define all your functions on the exports object
exports.foo = function() {
return 'bar';
};
})((typeof process === 'undefined' || !process.versions)
@oslego
oslego / javascript_multiton.js
Created June 3, 2011 10:57
JavaScript Multiton Example
/*
Use, reuse but don't abuse!
Author: Razvan Caliman (razvan.caliman@gmail.com)
This is an example of a "Multiton" pattern;
Create a fixed number of instances of a class.
Use "lazy instantiation" to create objects only if needed.
If the maximum number of instances has been reached, return a random one from the ones created.
*/
@creationix
creationix / chatServer.js
Created November 19, 2010 20:47
A simple TCP based chat server written in node.js
// Load the TCP Library
net = require('net');
// Keep track of the chat clients
var clients = [];
// Start a TCP Server
net.createServer(function (socket) {
// Identify this client
@katylava
katylava / git-selective-merge.md
Last active February 27, 2024 10:18
git selective merge

Update 2022: git checkout -p <other-branch> is basically a shortcut for all this.

FYI This was written in 2010, though I guess people still find it useful at least as of 2021. I haven't had to do it ever again, so if it goes out of date I probably won't know.

Example: You have a branch refactor that is quite different from master. You can't merge all of the commits, or even every hunk in any single commit or master will break, but you have made a lot of improvements there that you would like to bring over to master.

Note: This will not preserve the original change authors. Only use if necessary, or if you don't mind losing that information, or if you are only merging your own work.