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
// binding both "this" object and optionally arguments | |
if (!Function.prototype.bind) { | |
Function.prototype.bind = function bind(thisObject) { | |
var fun = this, boundArgs = Array.prototype.slice.call(arguments, 1); | |
return function() { | |
var allArgs = boundArgs; | |
if (arguments.length) { | |
allArgs = allArgs.concat(Array.prototype.slice.call(arguments)); | |
} |
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
// binding "this" object only (function arguments are ignored) | |
if (!Function.prototype.bind) { | |
Function.prototype.bind = function bind(thisObject) { | |
var fun = this; | |
return function() { | |
fun.apply(thisObject, arguments); | |
}; | |
}; | |
} |
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
if (!Function.prototype.curry) { | |
(function () { | |
var slice = Array.prototype.slice; | |
Function.prototype.curry = function () { | |
var target = this; | |
var args = slice.call(arguments); | |
return function () { | |
var allArgs = args; |
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
function fib(x) { | |
if (x < 2) | |
return 1; | |
return fib(x-1) + fib(x-2); | |
} |
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
(function () { | |
function iterator(collection) { | |
var index = 0; | |
var length = collection.length; | |
function next() { | |
var item = collection[index++]; | |
return item; | |
} |
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
var MainView = Backbone.View.extend({ | |
el: 'body', | |
events: { | |
'click #open': 'openModal' | |
}, | |
template: '<a id="open" class="btn">open modal</a>', | |
openModal: function() { | |
var view = new ModalView(); | |
var modal = new Backbone.BootstrapModal({ | |
content: view, |
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
var ModalView = Backbone.View.extend({ | |
tagName: 'p', | |
template: 'this is modal content', | |
render: function() { | |
this.$el.html(this.template); | |
return this; | |
} | |
}); | |
$(document).ready(function() { |
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
#!/usr/bin/php -q | |
<?php | |
set_time_limit(0); | |
ob_implicit_flush(); | |
if ($argc != 2) | |
die("Simple Time Server (C) 2013 Tomasz Ducin\n" . | |
"Invalid parameters passed\n" . | |
"Run:\n\t./time-server.php <port>\n" . |
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
var Class = function(base){ | |
if (typeof base.construct !== "function") | |
throw new TypeError("class definition has to define 'construct' function"); | |
return function() { | |
// copy all methods | |
for (var prop in base) { | |
if (base.hasOwnProperty(prop) && base[prop] !== base.construct) { | |
this[prop] = base[prop]; | |
} | |
} |
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
import os | |
parent_pid = os.getpid() | |
print "[parent] starts PID: %d" % (parent_pid, ) | |
forked_pid = os.fork() | |
if forked_pid == 0: | |
print "[child] child process can't use os.fork() PID, since it's %d" % (forked_pid, ) | |
print "[child] but it can reevaluate os.getpid() to get it's own PID: %d" % (os.getpid(), ) | |
else: |