Skip to content

Instantly share code, notes, and snippets.

View patrickbucher's full-sized avatar

Patrick Bucher patrickbucher

View GitHub Profile
package main
import (
"fmt"
"math/rand"
"strings"
"time"
)
var (
program p() {
while (halts(p) {
p();
}
}
package main
import "fmt"
type Numeric interface {
~int | ~float32 | ~float64
}
type Predicate[T any] func(T) bool
type Transform[T any] func(T) T
@patrickbucher
patrickbucher / dfde-threads.py
Created June 20, 2022 19:13
Exercise for DFDE Regexp Tutorial: Extract Thread Information from Sub-Forum
#!/usr/bin/env python3
from datetime import datetime
import re
import requests
import sys
def get_forum_text(forum_id):
url = f'https://debianforum.de/forum/viewforum.php?f={forum_id}'
package main
import "fmt"
type Numeric interface {
~int | ~float32 | ~float64
}
type Predicate[T any] func(T) bool
type Transform[T any] func(T) T
@patrickbucher
patrickbucher / choice.pl
Created February 19, 2022 15:55
Finding the optimal choice for everybody.
:- use_module(library(clpr)).
alice(apple, 1).
alice(banana, 2).
alice(orange, 3).
alice(kiwi, 4).
bob(apple, 1).
bob(orange, 2).
bob(banana, 3).
@patrickbucher
patrickbucher / oop_vs_fp.py
Created January 30, 2021 08:48
Object-Oriented Programming vs. Functional Programming: Trivial Example in Python
#!/usr/bin/env python3
# Object-Oriented Programming:
# - verbose
# - mutable state
class Rounding:
def __init__(self, granularity):
self._granularity = granularity
@patrickbucher
patrickbucher / virgp.sh
Last active August 2, 2019 13:30
open resulting files from ripgrep search tabbed in vim
# sample usage:
# $ cd /home/paedu/c
# $ virgp stdio
function virgp {
files="$(rg -l $1 | tr '\n' ' ')"
if [ -z "$files" ]
then
echo "pattern $1 did not match any files"
else
#echo "vim -p ${files}"
from encodings.aliases import aliases
for a in aliases:
try:
print('ö'.encode('utf-8').decode(a), a)
except:
pass
@patrickbucher
patrickbucher / formula1.pl
Last active October 21, 2018 19:26
Will Hamilton become World Champion in the 2018 US Grand Prix?
:- use_module(library(clpfd)).
points(1, 25).
points(2, 18).
points(3, 15).
points(4, 12).
points(5, 10).
points(6, 8).
points(7, 6).
points(8, 4).