Skip to content

Instantly share code, notes, and snippets.

View tmtvl's full-sized avatar
💭
Relaxed

Tim Van den Langenbergh tmtvl

💭
Relaxed
View GitHub Profile
@tmtvl
tmtvl / roman-dogs.scm
Created April 25, 2022 19:15
Scheme program to calculate the amount of dog names we could shove in a database.
(import (scheme base)
(scheme case-lambda)
(scheme file)
(scheme lazy)
(scheme write))
(define (filter pred lst)
(cond ((null? lst)
'())
((pred (car lst))
@tmtvl
tmtvl / power.org
Last active January 24, 2022 16:08
Converting stats from the EIA to terawatt.

Power

#+header-args: :cache yes :session power

Units

(import (scheme base))
@tmtvl
tmtvl / md5.c
Created December 9, 2021 22:53
Implementation of MD5 algo based on https://en.wikipedia.org/wiki/MD5
// Based on <https://en.wikipedia.org/wiki/MD5>
/************/
/* INCLUDES */
/************/
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@tmtvl
tmtvl / literate-programming-with-raku.md
Last active November 22, 2020 09:21
Article for Raku Advent 2020

Literate Programming with Raku

Different programming language communities have differing cultures. Some are more pragmatic, others more idealistic. Some place great emphasis on having code be thoroughly readable and understandable for anyone who joins an existing project, and some prefer writing out clear and in-depth documentation.

Raku, inheriting one of the best parts of Perl, has a community that writes great documentation.

What is Literate Programming?

Literate Programming is an alternate take on documentation. Instead of having the code be the central element and writing documentation around it, in Literate Programming we write a document that contains the essential parts of our program. In this way we integrate the code into our natural language in such a manner that the idea underlying the design is clear. In this way we also naturally start thinking explicitly about the operations our programs need to perform to fulfill the task we are se

@tmtvl
tmtvl / y-combinator.raku
Created June 24, 2020 14:14
Y Combinator
say sub ($f, $x, $y) {
return $f($x, $y, $f);
}(sub ($x, $y, $f) {
if $x < 2 {
return $y;
}
else {
return $f($x - 1, $x * $y, $f);
}
},
@tmtvl
tmtvl / fib.raku
Created May 18, 2020 12:52
Memoized fibonacci in Raku
#!/usr/bin/env raku
use v6;
sub memoize-walk (Code $calc --> Code) {
my Int @cache;
return sub (Int $n --> Int) {
return @cache[$n] if @cache[$n];
my Int $result = $calc($n);
@tmtvl
tmtvl / rnr.md
Created December 10, 2019 16:48
Raku advent 2019 day 13 RNR

A little R&R

Introduction

Raku is a really nice language. Versatile, expressive, fast, dwimmy. The only problem I sometimes have with it is that it can be a little slow. Fortunately that can easily be solved by the NativeCall interface, which makes it easy to call C code in your Raku program. Now, as nice as C is, it is a rather old language with some limitations. A newer language that can fill its niche is known as Rust. I'll show some examples of having Raku talk to Rust.

FFI

Rust code can be called from other languages using the FFI standard. FFI stands for "Foreign Function Interface" and allows you to export a Rust library as a standard shared library (a .so file on Linux or .dll on Windows). This is done by adding the following section in your Cargo.toml:

@tmtvl
tmtvl / basic.png
Last active November 27, 2019 20:41
Stackframe Reduction
basic.png
@tmtvl
tmtvl / replit_all_languages.json
Created October 3, 2019 12:42
repl.it all languages
{
"riddlejs": {
"ext": "js",
"template": "",
"hasInterpreter": true,
"entrypoint": "index.js",
"hasLanguageServer": true,
"icon": "https://repl.it/public/images/languages/nodejs.svg",
"category": "Hidden",
"hasProjectMode": true,
@tmtvl
tmtvl / perl6-notes.md
Last active July 28, 2019 19:59
Perl 6 notes

Perl 6 notes

Typing

do-a-thing(Array[Rat].new(0.5, 1.5));

Grepping out Rats