Skip to content

Instantly share code, notes, and snippets.

View dhilst's full-sized avatar
😻

Daniel Hilst dhilst

😻
View GitHub Profile
@dhilst
dhilst / clone.pl
Created February 9, 2026 04:29
Portabel perl clone function for clone objects
use strict;
use warnings;
use Test::More;
############################
# code under test
############################
sub clone {
@dhilst
dhilst / Buffer2d.pm
Last active February 12, 2026 16:46
use v5.36;
use Data::Dumper;
use Test::More;
use Test::Exception;
no autovivification;
sub aref { \@_ }
sub getters(@fields) {
@dhilst
dhilst / adt.pl
Last active February 9, 2026 04:45
use v5.10;
use Data::Dumper;
use Carp;
use Test::More;
sub aref { \@_ }
package Opt {
use overload
'""' => \&stringinfy;
use strict;
use warnings;
use feature 'say';
use Data::Dumper;
use Test::More;
use Scalar::Util qw(looks_like_number);
sub grep_str {
my $lines = shift;
my %acc;
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use File::Find;
use Getopt::Long qw(GetOptions :config no_bundling);
use Data::Dumper qw(Dumper);
#include <iostream>
#include <memory>
namespace foo {
// Here is how to create read only objects in C++23
// Step 1, define a class
class foo {
@dhilst
dhilst / phantomtypes.cpp
Created April 16, 2025 14:11
Type safe primitives in C++
// Phantom is a phatom type. It means that it is not used
// during runtime, but play type safety roles during compile
// time.
template <typename Phantom>
struct StrongId {
int id;
// Conversion int -> StrongId<T> must to be explicit
explicit StrongId(auto id_) : id(id_) {}
#![feature(try_blocks, try_trait_v2)]
#![allow(dead_code)]
#[derive(Debug)]
struct Foo<T>(T);
// Parametric types are bound during method calls
trait Bar<T> {
// Associated types are bound during Trait implementation
type AT;
from lark import Lark, Transformer, v_args
# 1. Define the grammar for second order logic using ASCII characters
grammar = """
start: formula
?expr: arith_expr
| bool_expr
?arith_expr: term
@dhilst
dhilst / README.md
Last active February 11, 2024 16:20
sexp parsing fun

A simple boolean language with definitions implemented over Sexp.t

Conclusions:

  • Is pretty easy to write a custom sexp_of_t and t_of_sexp functions.
  • This lets us to add some sugar over the atoms, I use ?v for variables as an example here
  • On top of that we can build superset of S-Expressions language which is easy to parse and very expressive

!!!! from manual !!!!

@TODO: FIX THIS!