Skip to content

Instantly share code, notes, and snippets.

@djedr
djedr / lisperator-problem-extended-25-11-2016.js
Last active May 29, 2019 19:38
My solution to "A little JavaScript problem" from lisperator.net [ http://lisperator.net/blog/a-little-javascript-problem/ ], with comments.
/**
* @file Solution to "A little JavaScript problem" from [lisperator.net]{@link http://lisperator.net/blog/a-little-javascript-problem/}.
*
* For demonstration. Overdocumented on purpose. Documentation is in a JSDoc-like documentation style.
* The solution itself is 7 SLOC.
* I also included test code to automatically verify correctness of the solution.
* See {@link https://gist.github.com/djedr/68fdaef3cad134788caefac06388534c} for a version without documentation or test code.
*
* Assumes ES6 support.
* Uses nested closures to emulate singly linked lists.
@djedr
djedr / 2017-02-01.md
Last active December 28, 2023 15:23
Combining the C preprocessor and JavaScript

Note

This text is superseded by https://gist.github.com/djedr/7d21eac05ce2bbbca29b29d532a1fbe4.

Why

There are some reasons listed here. To expand on that, using the C preprocessor with JavaScript project also gives us an easy way to share constants between different files. Back-end (Node.js) and front-end (Angular, React). But you can also share constants between .js files and .css files or any other text formats. No fuss. Just #include "constants.cpp".

Macros that operate on plain text are more limited and sloppier than macros that operate on syntax trees, like sweet.js. But they are also simpler. And very often enough.

Also:

  • cpp is simple

General-purpose text preprocessing with the C preprocessor. Featuring JavaScript.

2017-02-15 Dariusz Jędrzejczak

http://djedr.github.io


Outline

@djedr
djedr / talk--static-types-and-javascript--2017-03-08.md
Last active March 8, 2017 18:03
Static types and JavaScript. TypeScript and Flow

Static types and JavaScript

2017-03-08

Dariusz Jędrzejczak

http://djedr.github.io

This is a quick overview and comparison of TypeScript and Flow compiled from different sources (see links throughout and at the end of this document).

@djedr
djedr / xsv.js
Last active August 19, 2021 23:55
A simplistic parser for an imaginary XSV format -- a simplified, configurable variant of CSV
// A simplistic parser for an imaginary XSV format -- a simplified, configurable variant of CSV
// where the first 3 characters specify (in order):
// 1. the escape character (a backslash "\" in the example below)
// 2. the column separator (a comma "," in the example below)
// 3. the row separator (a newline character "\n" in the example below)
const parseXsv = (input) => {
console.assert(input.length >= 3)
const escape = input[0]
const columnSeparator = input[1]
const rowSeparator = input[2]
@djedr
djedr / grammar.abnf
Created January 9, 2022 23:55
A nice grammar for Jevko
Value = Subvalues Suffix
Subvalue = Prefix "[" Value "]"
Subvalues = *Subvalue
Suffix = *Char
Prefix = *Char
Char = Escape / %x0-5a / %x5c / %x5e-5f / %x61-10ffff
Escape = "`" ("`" / "[" / "]")
@djedr
djedr / easyjevko.js
Last active October 1, 2022 22:33
A simple data format built on Jevko
// run this script with
//
// node --experimental-network-imports easyjevko.js
//
// on Node.js or
//
// deno run --allow-net easyjevko.js
//
// on Deno

The main tricks I came up with in LAST are precisely basing it on quaternary and making up S-optimization. The former allows for streamlining of the basic BLC interpreter design (the 4 paths that handle the basic term elements are simplified), while the latter capitalizes on that by reducing repetition (nb. making the whole thing more efficient). I spent quite a bit of time working out and automating S-optimimization -- which is certainly the most interesting aspect of LAST and what sets it apart from RFNHS3 or other LC variants. I think it's pretty neat.

So of course if we get rid of the quaternary input, we'll immediately lose the advantage.

I noticed that using two separate tokens for variable handling allows BLC to interpret LAST in only 193 bits.

I think you can get that down to 181 bits, assuming 1:1 translation of S-deoptimized version of the LAST self-interpreter into BLC syntax (so not a valid BLC program, because the assumed input is different). Anyway 193 bits is also nice and I like how it's

@djedr
djedr / ron-to-djevko.md
Last active April 23, 2023 14:04
RON -> Djevko
const smartQueryString = ((strs, ...params) => {
let ret = ''
for (let i = 0; i < strs.length - 1; ++i) {
const str = strs[i]
const param = params[i]
// or whatever escaping method is appropriate
ret += str + encodeURIComponent(param)
}
return ret
})