Skip to content

Instantly share code, notes, and snippets.

View patrickbucher's full-sized avatar

Patrick Bucher patrickbucher

View GitHub Profile
@patrickbucher
patrickbucher / templates.go
Created February 14, 2024 07:24
Trying out Go Templates
package main
import (
"os"
"text/template"
"time"
)
type Article struct {
Title string
@patrickbucher
patrickbucher / systemd-service-dependency-graph.sh
Last active November 7, 2023 15:54
systemd service dependency graph
systemd-analyze dot --to-pattern='*.service' | \
sed '2i graph[overlap=false dpi=150]; node[fontname="monospace" shape=rect];' | \
nop | \ # obsessive-compulsive disorder
twopi -Tpng > systemd.png
@patrickbucher
patrickbucher / howto-shared-libraries.md
Created November 6, 2023 15:57
Shared Libraries Howto

Shared Libraries

Go to /home/user/libraries for this example:

$ mkdir /home/user/libraries
$ cd /home/user/libraries

Code

Library header (fib.h):

@patrickbucher
patrickbucher / sieve.py
Created July 17, 2023 17:28
Sieve of Eratosthenes in Python
#!/usr/bin/env python3
from functools import reduce
def sieve(xs):
return reduce(
lambda primes, x: primes + [x]
if not any(filter(lambda p: x % p == 0, primes))
else primes,
#!/usr/bin/env python3
import re
import sys
from huffman import Node
from huffman import count_frequencies
from huffman import build_tree
import pydot
#!/usr/bin/env python3
from collections import namedtuple
from bitstream import BitStream
Node = namedtuple('Node', 'chars weight left right')
left = False
Was bedeutet «Cloud Computing»?
Patrick Bucher, Modul 346, BBZW Sursee
2022-12-15
[Hierbei handelt es sich um eine unautorisierte Übersetzung. Die selben
Begriffe im Original wurden je nach Kontext und Bedarf anders übersetzt.
Bei ambivalenten Übersetzungen wird der englische Originalbegriff in
Klammern und kursivgesetzt angegeben.]
Cloud Computing ist ein Modell zur Ermöglichung eines allgegenwärtigen
package main
import (
"errors"
"fmt"
)
type Number float64
type Operator func(Number) Number
#!/usr/bin/env python3
from functools import reduce
from operator import mul
# the probability that it will rain in the next hour
rain_probs = {
1200: 0.05,
1300: 0.05,
1400: 0.05,
package errmonad
type ErrMonad[T any] struct {
Val T
Err error
}
type LiftFunc[T any] func(T) ErrMonad[T]
func Lift[T any](x T) ErrMonad[T] {