Skip to content

Instantly share code, notes, and snippets.

View hildjj's full-sized avatar

Joe Hildebrand hildjj

View GitHub Profile
@hildjj
hildjj / tagged-vector-adder.pegjs
Last active December 3, 2023 20:08 — forked from frostburn/tagged-vector-adder.pegjs
Peggy proposition: Tagged template parser with auto-vectorization of template arguments
import peg from "peggy-tag";
const PLACEHOLDER = "{{{ARG}}}";
const parse = peg`
{{
function add(left, right) {
if (typeof left === 'number') {
if (typeof right === 'number') {
return left + right;
@hildjj
hildjj / ISO-6093.pegjs
Created August 22, 2023 19:48
Aggressively accurate ISO 6093 parser
{{
// The signed representation of the numerical value zero shall contain a PLUS
// SIGN or a SPACE, but not a MINUS SIGN.
const NZERO1 = /^-0+$/
// The signed representation of the numerical value zero shall contain a PLUS
// SIGN or a SPACE, but not a MINUS SIGN.
const NZERO2 = /^-0*\.0*$/
// If the exponent has the value Zero, its sign shall be a PLUS SIGN.
@hildjj
hildjj / compress.js
Created September 6, 2022 17:48
Pipes are binary safe
// Compress a given string using the lzma program, and return the compressed contents.
const { spawn } = require('child_process')
const compress = str => new Promise((resolve, reject) => {
const lzma = spawn('cat',
{ stdio: ["pipe", "pipe", "inherit"] })
@hildjj
hildjj / bench.js
Created September 6, 2022 02:16
editorconfig parser comparison
/* eslint-disable no-console */
import { Benchmark } from 'kelonio'
import { parse } from './iniFile'
import { parse_to_json } from './one-ini/editorconfig_ini'
import { promises as fs } from 'fs'
import * as path from 'path'
interface WasmParseResults {
version: string
body?: (WasmPair | WasmComment | WasmSection)[]
@hildjj
hildjj / author.jq
Created January 9, 2022 20:18
Find all of the npm packages by a given author, so you can ensure you are either supporting them or switching to another package
# Run with npm ls --all --long --json --silent 2>/dev/null | jq -f author.jq --arg author <authorName>
# consider adding -g to the npm portion.
[
.. |
select(
objects |
has("author") and ((
.author | strings | contains($author)
) or (
@hildjj
hildjj / ships.rb
Created July 20, 2021 23:25
battleship
known_ships = [
["Cruiser", 3],
["Submarine", 2]
]
cells = []
%w( A B C D ).each do |x|
(1..4).each do |y|
cells << "#{x}#{y}"
end
@hildjj
hildjj / js-itertools.js
Created January 19, 2021 20:38
time node js-itertools.js
'use strict'
/**
* Is the given thing iterable?
*
* @static
* @param {any} g - the thing to check
* @returns {boolean} - true if `g` looks like an iterable
*/
function isIterable(g) {
@hildjj
hildjj / js-combinatorics-slow.js
Created January 19, 2021 20:35
time node js-combinatorics-slow.js
'use strict'
const req = require('esm')(module)
const {Combination} = req('js-combinatorics')
const a = Array.from(new Array(200), (_, i) => i)
let tot = 0
for (const [x, y, z] of Combination.of(a, 3)) {
tot += x*y*z
}
@hildjj
hildjj / Firefox Lines
Last active August 28, 2018 18:58
Firefox lines of code (from tokei)
$ tokei . -e third_party -s lines
--------------------------------------------------------------------------------
Language Files Lines Code Comments Blanks
--------------------------------------------------------------------------------
C++ 10956 5753882 4411352 595301 747229
JavaScript 58163 5690253 3657219 1214057 818977
HTML 66717 3471374 3005413 130585 335376
C Header 13935 2871337 1710080 754980 406277
C 2999 2112200 1514317 351977 245906
JSON 1174 1162180 1162180 0 0
'use strict'
class Frozen {
constructor() {
Object.freeze(this);
}
bar(...args) {
console.log('bar', ...args);
}
}