Skip to content

Instantly share code, notes, and snippets.

View mraleph's full-sized avatar
🐌

Slava Egorov mraleph

🐌
View GitHub Profile
@mraleph
mraleph / gist:3397008
Created August 19, 2012 18:48
simple and incomplete explanation of V8 strings

There are two types (actually more, but for the problem at hand only these two are important):

  • flat strings are immutable arrays of characters

  • cons strings are pairs of strings, result of concatenation.

If you concat a and b you get a cons-string (a, b) that represents result of concatenation. If you later concat d to that you get another cons-string ((a, b), d).

Indexing into such a "tree-like" string is not O(1) so to make it faster V8 flattens the string when you index: copies all characters into a flat string.

var a = "a";
var b = [];
for (var i = 0; i < 10; i++) {
a += a;
b.push(a);
}
b = b.join('');
@mraleph
mraleph / gist:3820878
Created October 2, 2012 16:41
__proto__ is awesome
whitestar ~/src/temp ∳ cat test.ts
__proto__("I like magical properties!");
whitestar ~/src/temp ∳ tsc test.ts
/Users/mraleph/local/node-v0.8.10/lib/node_modules/typescript/bin/tsc.js:19974
while(tok.tokenId != TypeScript.TokenID.EOF) {
^
TypeError: Cannot read property 'tokenId' of undefined
at Object.preProcessFile (/Users/mraleph/local/node-v0.8.10/lib/node_modules/typescript/bin/tsc.js:19974:18)
at CodeResolver.resolveCode (/Users/mraleph/local/node-v0.8.10/lib/node_modules/typescript/bin/tsc.js:19731:59)
@mraleph
mraleph / matmul1.dart
Created October 20, 2012 08:37
matmul dart benchmark
import 'dart:scalarlist'; // [!] added import
mat_transpose(a)
{
int m = a.length, n = a[0].length; // m rows and n cols
var b = new List(n);
for (int j = 0; j < n; ++j) b[j] = new Float64List(m); // [!] converted List<double> to Float64List
for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j)
b[j][i] = a[i][j];
@mraleph
mraleph / gist:4555694
Created January 17, 2013 12:43
Apollinaire
The second poem starts with
The sounds of horn
Startles those
Those who were not sleeping in shacks.
beautiful stranger
Came, riding the horse,
And he saw
a beautiful women,
Put her on the horse
Take the following countable signature:
true
false
undefined
null
ref1, ref2, ..., refN, ...
str1, str2, ..., strN, ...
pair(x, y)
object(x, y)
@mraleph
mraleph / gist:5129280
Created March 10, 2013 16:32
Literal translation of Victor Tsoi's "Хочу Перемен!" ("[I] want changes!").
Instead of warmth - the greenth of [bottle’s] glass,
Instead of fire - smoke
The day was snatched out of calendar’s grid.
Red sun is burning to ashes,
The day is burning out with it,
A shadow is falling over the glowing city
Changes!
[that is what] our hearts demand.
Changes!

One day a student came to Moon and said: “I understand how to make a better garbage collector. We must keep a reference count of the pointers to each cons.”

Moon patiently told the student the following story: “One day a student came to Moon and said: ‘I understand how to make a better garbage collector...

∮ node --version [master@fb796]
v0.10.8
∮ node -e "console.log(process.versions.v8)" [master@fb796]
3.14.5.9
∮ node experiment.js [master@fb796]
Running experiment with dimensions = 16 x 16 x 16
Proposal #1 array of native arrays Total Init = 1ms Execution = 32ms
Running experiment with dimensions = 64 x 64 x 64
class Step {
operator - (_) => this;
operator > (other) => new Seq(this, other);
}
class Atom extends Step {
final name;
Atom(this.name);