Skip to content

Instantly share code, notes, and snippets.

View NV's full-sized avatar

Nikita Vasilyev NV

View GitHub Profile
@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 / 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") +'"');
}
<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 / 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() {
<html>
<head>
<title>modify text bench</title>
</head>
<body>
<table>
<tr>
<td>div.appendChild(document.createTextNode( text ))</td>
<td id="text_node"></td>
@NV
NV / run-webkit-tests_output.txt
Created June 17, 2010 16:57
Problem with DumpRenderTree
WebKit$ WebKitTools/Scripts/run-webkit-tests
Running build-dumprendertree
=== BUILDING NATIVE TARGET DumpRenderTree OF PROJECT DumpRenderTree WITH CONFIGURATION Release ===
Checking Dependencies...
CompileC /Users/nikitavasilev/Code/WebKit/WebKitBuild/DumpRenderTree.build/Release/DumpRenderTree.build/Objects-normal/i386/AccessibilityController.o /Users/nikitavasilev/Code/WebKit/WebKitTools/DumpRenderTree/AccessibilityController.cpp normal i386 c++ com.apple.compilers.gcc.4_2
cd /Users/nikitavasilev/Code/WebKit/WebKitTools/DumpRenderTree
/Developer/usr/bin/gcc-4.2 -x c++ -arch i386 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -Os -mdynamic-no-pic -Werror -Wunused-function -Wunused-variable -DENABLE_DASHBOARD_SUPPORT -DWEBKIT_VERSION_MIN_REQUIRED=WEBKIT_VERSION_LATEST -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-declarations -mmacosx-version-min=10.5 -gdwarf-2 -I/Users/nikitavasilev/Code/WebKit/WebKitBuild/DumpRenderTree.build/Release/DumpRenderTree.build/Dump
const ITERATIONS = 100000;
(function(){
var start = new Date;
for (var i=0; i<ITERATIONS; ++i) {
Math.floor((i + ITERATIONS) / 2);
}
var end = new Date;
print("Math.floor: "+ (end - start) +"ms");
})();
var TOTAL = 3000;
// Prepare test data
var b = [];
for (var i=0; i<TOTAL; ++i) {
b[i] = [i];
}
(function(){
(function(){
print("Hello World!");
})();