Skip to content

Instantly share code, notes, and snippets.

View NV's full-sized avatar

Nikita Vasilyev NV

View GitHub Profile
@NV
NV / function.bind.js
Created June 2, 2010 18:41
Better function.bind()
// Better function.bind()
// Origin http://twitpic.com/1tbwip
// Inspired by http://perfectionkills.com/semantic-constructors/
Function.prototype.bind = function bind(thisObject) {
var func = this;
var args = Array.prototype.slice.call(arguments, 1);
function bound() {
return func.apply(thisObject, args.concat(Array.prototype.slice.call(arguments, 0)));
}
bound.toString = function toString() {
<script>
KeyboardEvent.prototype.__defineGetter__('character', function(){
return (this.ctrlKey || this.altKey || this.metaKey || !this.charCode)
? ""
: String.fromCharCode(this.charCode);
});
onkeypress = function(e){
document.getElementById('char').innerHTML += e.character + ' '
}
@NV
NV / unicode_to_actual_character.js
Created April 23, 2010 23:38
Convert unicode sequence to actual character. Like "U+005A" to "Z".
function unicodeToActualCharacter(code) {
// Convert unicode sequence to actual character
//
// unicodeToActualCharacter('U+005A') --> "Z"
return eval('"'+ code.replace("U+", "\\u") +'"');
}
@NV
NV / README.md
Created April 12, 2010 11:28
JavaScript Timer class. setInterval pool. Much more powerful than prototype.js's periodicalExecuter

JavaScript Timer

Run 5 times, with one second delay between calls

t1 = new Timer(500, function(){
  console.log(this.count);
  if (this.count >= 5) {
    this.stop();
  }

});

@NV
NV / chain.js
Created April 12, 2010 02:19
JavaScript chaining
function chain(fn){
// Chain factory
var list = [fn];
return function oneChain(fn){
if (arguments.length) {
list.push(fn);
return oneChain;
} else {
var result;
while (list.length) {
@NV
NV / queue.js
Created April 12, 2010 00:14
queue(a, b, c)(arg) === c(b(a(arg)))
function queue(){
function runQueue(){
var result = arguments;
var args = runQueue.args;
for (var i=0; i<args.length; i++) {
result = [args[i].apply(this, result)];
}
return result[0];
}
runQueue.args = arguments;
@NV
NV / Google search domains
Created April 2, 2010 20:55
All checked manually
google.ac
google.ae
google.af
google.ag
google.am
google.com.ar
google.as
google.at
google.com.au
google.az
@NV
NV / README.md
Created March 24, 2010 19:31
XRefresh for Chrome

XRefresh for Chrome

Deprecated! Use LiveReload instead.

via xrefresh#17

How to use

  • ruby ws_dir_watcher.rb ~/my_site
  • Open chrome://extensions/
  • "Developer mode", then press "Load unpacked extension" button
@NV
NV / anonymous_class.rb
Created March 21, 2010 13:07
Ruby's anonymous classes
dog = 'Bob'
class << dog
def what
self
end
end
dog.what #'Bob'
''.what #NoMethodError
@NV
NV / README.md
Created March 18, 2010 14:14
UserScript. Replace tabs with 2 spaces

Tab size UserJS

8 spaces for the tab character is too many. I'd prefer 2.

Supported browsers: Firefox, Google Chrome, Opera, and Safari.

beforeafter