Skip to content

Instantly share code, notes, and snippets.

/**
* Apply a function in needed environment.
* Firefox only, educational purpose only.
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*/
Function.prototype.setEnvironment = function(environment) {
with (environment) {
return eval(uneval(this));
}
@DmitrySoshnikov
DmitrySoshnikov / pattern-matching.md
Last active August 29, 2015 14:05
Pattern Matching

Pattern Matching

In this article we briefly describe the generic topic of pattern matching in programming languages. We'll see that this powerful technique is present in our every day programming, even if we may not notice it.

Matching

A matching is a process of checking whether one thing has the same or similar representation as another thing.

There are two basic matches:

@DmitrySoshnikov
DmitrySoshnikov / union-quick-union.js
Created November 12, 2014 00:02
Union.QuickUnion
/**
* "Is connected?"
*
* Dynamic connectivity issue.
*
* 1 2: not connected
* 1--2: connected
* 1--2--3: 1 and 3 are connected through 2
*
* This implements quick union operation, but the find
@DmitrySoshnikov
DmitrySoshnikov / shadow-hoisting-tdz.md
Last active August 29, 2015 14:15
Shadow, hoisting, TDZ

1. A system without hoisting

An example of Scheme program without hoisting:

(define x 10)     ; global `x`
(print x)         ; 10

((lambda ()
    (print x)     ; still 10, not shadowed yet

ES7 String trim functions

String.prototype.trim ( )

Return result of StringTrim abstract operation passing this value as thisArg, and TrimBoth as the type.

String.prototype.trimRight ( )

Return result of StringTrim abstract operation passing this value as thisArg, and TrimRight as the type.

@DmitrySoshnikov
DmitrySoshnikov / AST-printer.js
Last active August 29, 2015 14:25
AST Printer / Code generator
/**
* = AST printer =
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style License
*
* Once we have finished operating on our AST, we need to generate the
* code back from that (possibly transformed) AST.
*
* We choose a very simple AST format here, which we used in the
@DmitrySoshnikov
DmitrySoshnikov / es2015-callable.js
Last active August 29, 2015 14:26
es2015-callable.js
/**
* Callable objects in ES2015.
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style License
*/
class Callable extends Function {
constructor() {
super('(' + Callable.prototype.__call__ + ')();');
return this.bind(this);
/* by Dmitry A. Soshnikov */
#include "stdafx.h"
#include <iostream>
struct Object {
int x;
int y;
};
/**
* Aliases and additional "sugar"
* 2010-04-15
* @author Dmitry A. Soshnikov
*/
(function () {
var
$break = {},
hasOwn = Object.prototype.hasOwnProperty;
C++ source:
void call_by_reference(int& x)
{
x = 20;
}
void call_by_pointer(int* x)
{
*x = 20;