Skip to content

Instantly share code, notes, and snippets.

View patrickbucher's full-sized avatar

Patrick Bucher patrickbucher

View GitHub Profile
- Software consists of algorithms and data structures. (Niklaus Wirth published
a book called _Algorithms = Data Structures = Programs_.)
- Algorithms work on data structures by manipulating them in place or by
transforming them into other data structures.
- Data structures are usually the starting and end point of a program.
Exceptions are programs that make up their own data (e.g. by generating
random data or by gathering measurements of sensors), but even then the
definition of the data structures predates the algorithm.
- The data structure an algorithm works on shall be called an _input data
structure_, and a data structure an algorithm is producing shall be called an
#!/usr/bin/awk
# sumtime.awk: sums up times
# input: lines with time indications of the form hh:mm, e.g. 12:30 or 4:15
# output: the sum of the times, e.g. 16:45
/[0-9]{1,}:[0-9]{1,2}/ {
split($0, fields, ":")
hours += fields[1]
minutes += fields[2]
}
@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