Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
DmitrySoshnikov / bound-functions.js
Created August 16, 2011 14:14
Features of bound functions
/**
* Features of bound functions.
*
* See: http://dmitrysoshnikov.com/notes/note-1-ecmascript-bound-functions/
*
* by Dmitry Soshnikov <[email protected]>
* MIT Style License
*/
var F = function () {};
@DmitrySoshnikov
DmitrySoshnikov / processes.js
Created August 7, 2011 07:52
Processes with supporting trampolining
/**
* The simplest processes (cooperative tasks) with Scheduler
* (sort of Erlang's processes but without messages yet)
* See: http://www.dabeaz.com/coroutines/index.html
*
* Deps: JS 1.7 with generators (yield)
*
* This version uses "trampolining" technique to request
* data from other processes in synchronous manner.
* See also: https://gist.github.com/1127536 (without "trampolining")
@DmitrySoshnikov
DmitrySoshnikov / erlang-scheduler.js
Created August 5, 2011 13:24
Simple (cooperative) processes with the Scheduler
/**
* The simplest processes (cooperative tasks) with Scheduler
* (sort of Erlang's processes but without messages yet)
* See also: http://www.dabeaz.com/coroutines/index.html
*
* Deps: JS 1.7 with generators (yield)
*
* by Dmitry Soshnikov <[email protected]>
* MIT Style License
*/
@DmitrySoshnikov
DmitrySoshnikov / primitive-process.html
Created July 25, 2011 08:18
Primitive Actor-processes
<html>
<head>
<title>Process</title>
<style type="text/css">
#p-0 {color: green;}
#p-1 {color: blue;}
.p {
float: left;
width: 300px;
border: 1px solid #CCC;
@DmitrySoshnikov
DmitrySoshnikov / es5-negative-indicies.js
Created May 21, 2011 21:32
Manual negative indicies of arrays in ES5
/**
* Manual negative indicies for arrays in ES5:
* usually we use in such cases only first three
* negative indices, so these are enough (you may
* add -4, -5, etc. if needed).
*
* See also the implementation with proxies:
* https://github.com/DmitrySoshnikov/es-laboratory/blob/master/src/array-negative-indices.js
*
* by Dmitry Soshnikov <[email protected]>
@DmitrySoshnikov
DmitrySoshnikov / classes.txt
Created May 17, 2011 18:19
Classification of classes
// by Dmitry Soshnikov <[email protected]>
// MIT Style License
*Classification of classes:*
=============================================================================
| Dynamic | Static
-----------------------------------------------------------------------------
| |
| Coffee, Python, Ruby, | SmallTalk, built-in
$coroutine = (func) -> ->
gen = func(arguments...)
gen.next()
gen
grep = $coroutine (pattern) ->
console.log "Looking for #{pattern}"
while true
line = yield
if line.indexOf pattern != -1
main([]) ->
%% Given the parsed HTML tree in the following format:
%%
%% Types HTML = [Element]
%% Element = {Tag, [Attribute], [Element | Text]}
%% Tag = atom() % e.g. 'a', 'pre', 'p'
%% Attribute = {Name, Value}
%% Name = atom()
%% Value = string()
main(_Arg) ->
HTML = {p, [{text, "test"}, {class, "bold"}], [
{span, [{text, "value"}, {class, "bold"}], [
{span, [{text, "hi"}, {class, "bold"}], []}
]}
]},
Texts = get_text(HTML, []),
% ["value","test"]
@DmitrySoshnikov
DmitrySoshnikov / harmony-modules-import.js
Created March 24, 2011 18:00
Harmony modules import
/**
* Test for module imports
* Tested in Narcissus
* by Dmitry Soshnikov
*/
module M {
export var x = 10;
export var y = 20;
}