Skip to content

Instantly share code, notes, and snippets.

@hoehrmann
hoehrmann / evolveProtocol.ts
Last active April 18, 2019 21:15
Idea for JSON-RPC 2.0 interface definitions using TypeScript
export namespace api {
export interface Request<T extends string> {
params: any;
result: any;
__name: {
[name in T]: T
}
}
@hoehrmann
hoehrmann / fdpassing.ts
Created April 14, 2019 21:49
node <> Perl communication over additional fds
import { spawn } from 'child_process';
import { Writable, Readable } from 'stream';
const child = spawn(
'perl',
['-e', `
use IO::Handle;
my $in = IO::Handle->new_from_fd($ENV{JIPE_RHS_STDIN_FD}, 'r');
my $out = IO::Handle->new_from_fd($ENV{JIPE_RHS_STDOUT_FD}, 'w');
@hoehrmann
hoehrmann / sqlite-stored-procedure.sql
Created October 15, 2018 22:53
Poor man's Stored Procedures with SQLite
DROP VIEW IF EXISTS stored_procedure_do;
CREATE VIEW IF NOT EXISTS stored_procedure_do
AS SELECT NULL AS json_args LIMIT 1;
DROP TABLE IF EXISTS stored_procedure_result;
CREATE TABLE IF NOT EXISTS stored_procedure_result(
json_result
);
DROP TRIGGER IF EXISTS stored_procedure_impl;
@hoehrmann
hoehrmann / sql-json-style-sheets.sql
Created October 6, 2018 16:44
Complex table formatting of SQL Query results using JSON formatting objects
-- styles for CPAN module Text::ANSITable
SELECT
time, priority, message
,
json_object(
'priority',
json_object(
'fgcolor',
CASE
Hi,
Using the sqlite-tools-linux-x86-3250100 Linux binaries I find that
Window functions in VIEWS behave differently from PostgreSQL 9.6 and
from what I expect.
DROP TABLE IF EXISTS example;
CREATE TABLE example(t INT, total INT);
INSERT INTO example VALUES(0,2);
INSERT INTO example VALUES(5,1);
@hoehrmann
hoehrmann / view_every_hour_past_six_months.sql
Last active December 22, 2021 23:38
view_every_hour_past_six_months.sql
DROP VIEW IF EXISTS view_every_hour_past_six_months;
CREATE VIEW view_every_hour_past_six_months AS
WITH RECURSIVE
bounds AS (
SELECT
strftime('%s', 'now', 'start of day', '-6 month') AS lower,
strftime('%s', 'now', 'start of day', '+1 day') AS upper
),
samples AS (
SELECT lower AS sample FROM bounds
@hoehrmann
hoehrmann / c11-lexer-grammar
Created June 22, 2018 22:10
C11 Lexer grammar
token = _
/ keyword
/ identifier
/ constant
/ string-literal
/ punctuator
preprocessing-token = _
/ header-name
/ identifier
SQLite version 3.11.0 2016-02-15 17:29:24
Enter ".help" for usage hints.
sqlite> EXPLAIN QUERY PLAN
...> WITH RECURSIVE path(pos, vertex) AS (
...> SELECT 0, ?
...> UNION ALL
...> SELECT path.pos + 1, (SELECT Edge.dst
...> FROM Edge
...> WHERE Edge.src = path.vertex
...> ORDER BY RANDOM()
@hoehrmann
hoehrmann / binops-all.txt
Created January 10, 2018 22:42
Binary boolean operation truth tables, various versions
0 !| < > & A B ==
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 | | 0 | 0 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
#!/bin/bash
#####################################################################
# Copyright (c) 2016 Bjoern Hoehrmann <bjoern@hoehrmann.de>. GPLv3+.
#
# Given image + color, creates mask encoding pixel's LAB color diff.
#####################################################################
path_in="$1"
color_rgb="$2"
path_out="$3"