Skip to content

Instantly share code, notes, and snippets.

Avatar

Peter Ludemann kamahen

View GitHub Profile
@kamahen
kamahen / pcre2_mingw.c
Created Apr 5, 2022
Output some PCRE2 values for debugging PCRE2 with MinGW
View pcre2_mingw.c
#include <stdio.h>
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
static void config_uint(const char *descr, uint32_t flag) {
uint32_t value;
uint32_t len = pcre2_config_8(flag, NULL);
int rc = pcre2_config_8(flag, &value);
if (rc >= 0) {
printf("%s (len=%d rc=%d) 0x%08x: 0x%08x\n", descr, len, rc, flag, value);
View edcg_valid_termpos.pl
:- det(valid_termpos/2).
%! valid_termpos(+Term, +TermPos) is semidet.
% Checks that a Term has an appropriate TermPos.
% This should always succeed:
% read_term(Term, [subterm_positions(TermPos)]),
% valid_termpos(Term, TermPos)
valid_termpos(_Term, Var), var(Var) => true. % trivial default: "unknown" position
valid_termpos(Atom, _From-_To), atom(Atom) => true.
valid_termpos(Number, _From-_To), number(Number) => true.
valid_termpos(Var, _From-_To), var(Var) => true.
@kamahen
kamahen / d_wire.pl
Created Jul 18, 2021
Test data for protobufs:proto_meta_field_name/4 indexing
View d_wire.pl
wire_codes(RequestWireStream) :-
RequestWireStream=[10,16,100,101,115,99,114,105,112,116,111,114,46,112,114,111,116,111,26,8,8,3,16,17,24,3,34,0,122,185,133,3,10,16,100,101,115,99,114,105,112,116,111,114,46,112,114,111,116,111,18,15,103,111,111,103,108,101,46,112,114,111,116,111,98,117,102,34,77,10,17,70,105,108,101,68,101,115,99,114,105,112,116,111,114,83,101,116,18,56,10,4,102,105,108,101,24,1,32,3,40,11,50,36,46,103,111,111,103,108,101,46,112,114,111,116,111,98,117,102,46,70,105,108,101,68,101,115,99,114,105,112,116,111,114,80,114,111,116,111,82,4,102,105,108,101,34,228,4,10,19,70,105,108,101,68,101,115,99,114,105,112,116,111,114,80,114,111,116,111,18,18,10,4,110,97,109,101,24,1,32,1,40,9,82,4,110,97,109,101,18,24,10,7,112,97,99,107,97,103,101,24,2,32,1,40,9,82,7,112,97,99,107,97,103,101,18,30,10,10,100,101,112,101,110,100,101,110,99,121,24,3,32,3,40,9,82,10,100,101,112,101,110,100,101,110,99,121,18,43,10,17,112,117,98,108,105,99,95,100,101,112,101,110,100,101,110,99,121,24,10,32,3,40,5,82,16,112,117,98,10
@kamahen
kamahen / coverage.pl
Created Jul 12, 2021
Hack on top of swipl library(test_cover) for more granular coverage
View coverage.pl
% -*- mode: Prolog -*-
/*
TODO: generalize this code to work in any file (currently, file name is hard-coded)
This code depends on a modification to ~/src/swipl-devel/packages/plunit/test_cover.pl:
$ git diff
diff --git a/test_cover.pl b/test_cover.pl
index 5290499..24d8874 100644
@kamahen
kamahen / tree_path.pl
Last active Mar 8, 2021
calculate path into a binary tree for some element
View tree_path.pl
% -*- mode: Prolog -*-
% See https://twitter.com/krismicinski/status/1368611779107053570?s=03
% gives a program in Racket; I've written my version in
% non-deterministic Prolog.
% Tested with SWI-Prolog 8.3.20
% (You can also try this out at https://swish.swi-prolog.org/)
% The problem is (using Racket terminology):