Skip to content

Instantly share code, notes, and snippets.

/**
* Stack buffer overflow.
*
* TL;DR: In older OSes, a buffer overflow of the data on the stack
* allowed overriding a return address, and execute an exploit code,
* instead of returning to a caller.
*
* Docs: https://en.wikipedia.org/wiki/Stack_buffer_overflow
*
* by Dmitry Soshnikov <[email protected]>
@DmitrySoshnikov
DmitrySoshnikov / eoi-ml-lesson1-ae.ml
Last active March 1, 2016 20:50
Essentials of interpretation, ML version: Lesson 1: Arithmetic expressions evaluator
(*
* "Essentials of interpretation. Semantics of programming languages"
*
* Lesson 1: Arithmetic expressions evaluator.
*
* BNF grammar:
*
* NUMBER -> \d+
*
* Exp -> NUMBER
@DmitrySoshnikov
DmitrySoshnikov / more-code-less-code.md
Last active February 27, 2016 19:49
x86: More code - less code

x86: More code - less code

Sometimes more code in a source language, can mean less code in a generated language.

NOTE: below we used gcc 5.3 with -std=c++14 -O3 flags.

On the example of C programming language, and its translation to x64 assembly, let's take a look at the following example:

// 7 times `x`.
@DmitrySoshnikov
DmitrySoshnikov / c-arrays-allocation.c
Last active February 19, 2016 00:08
Contiguous and non-contiguous C-arrays allocation
/**
* Contiguous and non-contiguous C-arrays allocation in memory.
* by Dmitry Soshnikov <[email protected]>
*/
#include <iostream>
int main()
{
// -----------------------------
@DmitrySoshnikov
DmitrySoshnikov / s-expression-parser.js
Last active October 9, 2023 05:59
S-expression parser
/**
* S-expression parser
*
* Recursive descent parser of a simplified sub-set of s-expressions.
*
* NOTE: the format of the programs is used in the "Essentials of interpretation"
* course: https://github.com/DmitrySoshnikov/Essentials-of-interpretation
*
* Grammar:
*
@DmitrySoshnikov
DmitrySoshnikov / asm-addr-mode.md
Last active January 19, 2017 03:07
Addressing modes in `mov`, and their C version
Addressing modes in mov, and their C version

Below are addressing modes (immediate, register, memory) on the examples of the mov assembly instruction. Here we use movl ("move long") for a 32-bit word.

Note: cannot move memory-to-memory, need two instructions.

Src
movl
@DmitrySoshnikov
DmitrySoshnikov / union-quick-union-weight.js
Created February 4, 2016 05:42
Union.QuickUnion.Weight
/**
* "Is connected?"
*
* Dynamic connectivity issue.
*
* 1 2: not connected
* 1--2: connected
* 1--2--3: 1 and 3 are connected through 2
*
* This implementation uses concept of a "weight" to avoid too long trees:
@DmitrySoshnikov
DmitrySoshnikov / delegation-based-prototypes.py
Last active January 30, 2016 09:23
Delegation-based prototypes: implementing JavaScript semantics in Python
###
# Explicit delegation-based prototypes implementation.
#
# Implementing JavaScript semantics.
#
# Here we show that "delegation" is just a mechanism (a pattern) for
# implementation of the "inheritance" concept. In this specific case we
# have direct inheritance from objects, skipping the "class" step.
#
# See "OO Relationships" article for some details:
@DmitrySoshnikov
DmitrySoshnikov / es2015-destructuring-reference-bindings.js
Last active January 24, 2016 05:32
ES2015: Destructuring reference bindings
/**
* Destructuring reference bindings.
*
* by Dmitry Soshnikov <[email protected]>
* MIT Style License
*/
// Bindings of a pattern in destructuring may be not only
// simple variables, but any reference types. In the following
// example we use destructuring assignment to swap two elements
@DmitrySoshnikov
DmitrySoshnikov / json.bnf
Created January 10, 2016 04:40
json.bnf
%token STRING NULL NUMBER TRUE FALSE
%start JSONText
%%
JSONText : JSONValue;
JSONString : STRING;