Skip to content

Instantly share code, notes, and snippets.

@hoehrmann
hoehrmann / gist:2395307
Created April 15, 2012 23:27
Merge Internet Archive OCR data with Google Books plain text into JSON
#!perl -w
use strict;
use warnings;
use XML::Parser;
use PerlIO::via::gzip;
use feature 'say';
use Archive::Zip;
use Image::Magick;
use Algorithm::Diff 'sdiff';
use List::Util qw/min max first/;
@hoehrmann
hoehrmann / force-prefix-init-script.bash
Created August 16, 2021 21:22
Bash: prefix output of all commands with timestamp
function process_command() {
if [ "$$" -eq "$BASHPID" ]; then
if [[ "$HANDLER_INSTALLED" -ne "1" ]]; then
exec > >(
trap "" INT TERM;
awk '{ print strftime("%Y-%m-%d %H:%M:%S ", systime()) $0; fflush(stdout) }'
)
exec 2> >(
trap "" INT TERM;
awk '{ print strftime("%Y-%m-%d %H:%M:%S ", systime()) $0; fflush(stdout) }' >&2
@hoehrmann
hoehrmann / lgpunp.pas
Created June 5, 2013 13:13
Final Fantasy VII (PC) .lgp package file extractor, anno 1998.
program LgpUnp;
(* Extracts Files from SquareSoft's Final Fantasy VII .LGP files *)
(* Copyright (c) 1998 by Bjoern Hoehrmann All rights reserved *)
var Index:record { Entry in the filelist at the beginning }
Name:array[0..19] of char; { Filename }
offset:longint; { FileOffset of this file }
res:longint; { Unused Data }
end;
@hoehrmann
hoehrmann / TEX2BMP.pas
Created June 6, 2013 10:41
Converter for .TEX texture files from SquareSoft's Final Fantasy VII to Windows BMP files.
{ _Add wildcards, parameter comfort, seperate file extraction for manipulation,
graphical output, check for xdim, memory using Speedup for swapping,..._ }
{$Q-}
program TEXfileUnpack;
(* Converts .TEX Files from SquareSoft's Final Fantasy VII TO BMP files *)
(* Copyright (c) 1998 by Bjoern Hoehrmann All rights reserved *)
type
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use JSON;
use YAML::XS;
my $dbh = DBI->connect('dbi:SQLite:dbname=:memory:');
our $Arg;
WITH
bytes AS (
SELECT 0x00 AS byte
UNION ALL
SELECT byte+1 FROM bytes WHERE byte < 0xFF
),
base AS (
SELECT 0x0000 AS cp
UNION ALL
SELECT cp+1 FROM base WHERE cp < 0x10FFFF
@hoehrmann
hoehrmann / set-intspan-partition.sql
Created May 5, 2019 21:44
SQL alternative for Set::IntSpan::Partition
WITH
args AS (
SELECT
'
[
[[1,3]],
[[3,5],[7,8]],
[[8,8]],
[[0,100]]
]
@hoehrmann
hoehrmann / vowels-vs-consonants.ts
Created April 19, 2019 22:21
NodeJS backpressure streams with prioritisation
const through2 = require('through2');
const split2 = require('split2');
var vowels = through2({ objectMode: true });
var consonants = through2({ objectMode: true });
var muxed = through2({ objectMode: true, highWaterMark: 1 });
[vowels, consonants].forEach(x => x.pipe(muxed));
muxed.pipe(process.stderr);
@hoehrmann
hoehrmann / evolveProtocol.ts
Created April 18, 2019 23:51
evolveProtocol
export namespace api {
export interface Request<
> {
method: string;
params: any;
result: any;
}
export interface Notification<
@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
}
}