Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
DmitrySoshnikov / math-expr-lexer.cpp
Created October 13, 2014 06:04
Simple math expression lexer.
// by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
// MIT Style License.
// Short URL for this example to run online is: http://cpp.sh/333
#include <iostream>
#include <vector>
#include <ctype.h>
#include <cstring>
/**
* NFA (Non-deterministic finite automata)
*
* A formalism for regular grammars (to recognize strings based on regular
* expressions).
*
* Regexp parser to transform AST to NFA:
* https://www.npmjs.com/package/regexp-tree
*
* NFA/DFA fragment examples:
@DmitrySoshnikov
DmitrySoshnikov / dfa-minimization.js
Last active May 21, 2021 09:39
DFA minimization
/**
* DFA minization.
*
* A DFA table is minimized using N-equivalence algorithm.
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*/
/**
* Non-minizied DFA table for `/a|b/`.
@DmitrySoshnikov
DmitrySoshnikov / NFA-DFA-RegExp.js
Last active May 21, 2021 08:41
Classic RegExp implementation (NFA, DFA)
/**
* Classic RegExp implementation (NFA, DFA).
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT License, 2017
*/
/**
* Epsilon.
*/
@DmitrySoshnikov
DmitrySoshnikov / calculator.ast.js
Last active May 14, 2021 08:36
calculator.ast.js
/**
* Calculator grammar for a parser in JavaScript.
*
* syntax-cli -g calculator.ast.js -m LALR1 -o CalcParser.js
*
* const CalcParser = require('./CalcParser.js');
* console.log(CalcParser.parse('2 + 2 * 2')); // AST
*/
{
; ___ _ __ ___ __ ___
; / __|_ _ __ _| |_____ / /| __|/ \_ )
; \__ \ ' \/ _` | / / -_) _ \__ \ () / /
; |___/_||_\__,_|_\_\___\___/___/\__/___|
; An annotated version of the snake example from Nick Morgan's 6502 assembly tutorial
; on http://skilldrick.github.io/easy6502/ that I created as an exercise for myself
; to learn a little bit about assembly. I **think** I understood everything, but I may
; also be completely wrong :-)
@DmitrySoshnikov
DmitrySoshnikov / json.bnf
Created January 10, 2016 04:40
json.bnf
%token STRING NULL NUMBER TRUE FALSE
%start JSONText
%%
JSONText : JSONValue;
JSONString : STRING;
/* by Dmitry A. Soshnikov */
var object = (function () {
// private
var _x = 10;
// also private
function _privateFunc() {
return _x;
@DmitrySoshnikov
DmitrySoshnikov / Map.prototype.filter.md
Created October 1, 2014 22:24
Map.prototype.filter

Map.prototype.filter ( callbackfn [ , thisArg ] )

NOTE callbackfn should be a function that accepts three arguments. filter calls callbackfn once for each key/value pair present in the map object, in key insertion order, and returns a new filtered map. callbackfn is called only for keys of the map which actually exist; it is not called for keys that have been deleted from the map.

If a thisArg parameter is provided, it will be used as the this value for each invocation of callbackfn. If it is not provided, undefined is used instead.

callbackfn is called with three arguments: the value of the item, the key of the item, and the Map object being traversed.

filter does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn.

@DmitrySoshnikov
DmitrySoshnikov / GIF-Screencast-OSX.md
Created January 30, 2020 07:37 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application: