This file contains 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
/* Bind one handler to many events | |
USAGE: | |
channel.bindMany('event1', 'event2', 'event3', function( data ){ | |
// do something | |
}) | |
-------------------------------------------------------*/ | |
Pusher.Channel.prototype.bindMany = function(){ | |
var handler = Array.prototype.pop.call(arguments); | |
for (var i = 0; i< arguments.length; i++){ | |
this.bind( arguments[i], handler ) |
This file contains 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
/* Dynamically require scripts in the browser, with async callback for when all dependencies are loaded | |
Example: | |
function pageReady() { | |
// Init your code here | |
alert('All dependencies loaded!'); | |
} | |
_require(['/json2.js', 'http://server.com/foo.js'], pageReady); |
This file contains 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
# This goes in vcl_recv | |
# It gives you: | |
# curl -X PURGE http://some.example.com/.* | |
# curl -X PURGE http://some.example.com/blog/.* | |
# curl -X PURGE http://some.example.com/blog/2011/bar.html | |
# curl -X PURGE http://another.example.com/.* | |
# | |
if (req.request == "PURGE") { | |
# Wildcard, per-domain purging | |
purge("req.http.host == " req.http.host " && req.url ~ " req.url "$"); |
This file contains 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
<html> | |
<head> | |
<title>JS Iterator</title> | |
<script> | |
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
// NOTE: SKIP TO USAGE EXAMPLE AT THE BOTTOM FOR OVERVIEW | |
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
function extend(one, two) { | |
for(var i in two){ | |
one[i] = two[i] |
This file contains 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
//++++++++++++++++++++++++++++++++++++++++++++++++ | |
// Basic FSM implementation | |
//++++++++++++++++++++++++++++++++++++++++++++++++ | |
var StateMachine = function(initial_state) { | |
var transitions = {}, | |
state_callbacks = {enter:{}, exit:{}}, | |
addTransition = function (from, to, guard) { | |
transitions[from] = transitions[from] || {}; | |
transitions[from][to] = guard || function () {return true}; |
This file contains 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
<!-- This is how you lay out cross-browser columns. Stick to this and you're golden --> | |
<style> | |
.clearfix:after { | |
content: "."; | |
display: block; | |
clear: both; | |
visibility: hidden; | |
line-height: 0; | |
height: 0; | |
} |
This file contains 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
/* Like Sammy.js but without the extra crap such as templating, and only for GETs and events | |
Features: | |
.get(path, handler) | |
Binds changes on the browser's location hash to a handler function, a la Sammy | |
.sub(event_name, handler) | |
Binds custom event name to event handler. Event names can have :tokens just like location hashes. Ie: |
This file contains 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
# thin start -R thin_async.ru -p 3000 | |
# | |
# ab -c 100 -n 500 http://127.0.0.1:3000/ | |
# | |
# Concurrency Level: 100 | |
# Time taken for tests: 8.888 seconds | |
# Complete requests: 500 | |
# Failed requests: 0 | |
# Write errors: 0 | |
# Total transferred: 6243500 bytes |
This file contains 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
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
Cycle array of URLs and process with phantom.js (http://www.phantomjs.org/) | |
Adds Array.prototype.forEachWebPage() iterator. | |
EXAMPLE: | |
Save screenshots. Command line: | |
phantomjs phantom_js_url_cycle.js ./screenshots | |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
[ |
This file contains 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
/* Bindable scopes for JsModel | |
Usage: | |
var User = Model('user', function () { | |
this.use(Model.Scopes) | |
}); | |
// Define scopes | |
User.scope('with_i', function (model) { | |
return /^i/i.test(model.attr('name')) |