From 3af714e89059739f365c3a92c8833864665ff497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 25 Jun 2023 06:41:04 +0200 Subject: =?UTF-8?q?s=C3=B6n=2025=20jun=202023=2006:41:04=20CEST?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Python Operators.wiki | 39 +++++++++++++++++++++++++++++++++++ Python Pipeline.wiki | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ Python.wiki | 4 +++- bolt.wiki | 9 +++++++++ index.wiki | 9 +++++---- puppet.wiki | 2 ++ 6 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 Python Operators.wiki create mode 100644 Python Pipeline.wiki create mode 100644 bolt.wiki diff --git a/Python Operators.wiki b/Python Operators.wiki new file mode 100644 index 0000000..aa9dbc1 --- /dev/null +++ b/Python Operators.wiki @@ -0,0 +1,39 @@ +{{{ +< __lt__ +<= __le__ +== __eq__ +!= __ne__ +>= __ge__ +> __gt_ + ++ __add__ +// __floordiv__ +~ __inv__ (or __invert__) +<< __lshift__ +% __mod__ +* __mul__ +@ __matmul__ +- (unary) __neg__ +| __or__ ++ (unary) __pos__ +>> __rshift__ +- __sub__ +/ __truediv__ +^ __xor__ ++ (sequences) __concat__ + +** __pow__ + +in __contains__ + +& __and__ + + +__abs__ +}}} + +{{{ +__bool__ +__str__ +__repr__ +}}} diff --git a/Python Pipeline.wiki b/Python Pipeline.wiki new file mode 100644 index 0000000..e91f93f --- /dev/null +++ b/Python Pipeline.wiki @@ -0,0 +1,56 @@ +{{{python +#!/usr/bin/env python3 + +import base64 +import hashlib +import os.path +import sys +from typing import Callable, Any +from dataclasses import dataclass + + +@dataclass +class Pipeline: + """ + A data pipeline. + + "Syntax" to allow functions and methods to be chained, similar to + clojures arrow operator (``->``). + + Each operation applies some kind of procedure, and forwards the + pipeline with the result (by returning a new Pipeline object with + the contained object being replaced: + + ``.do`` applies a function, passing the pipelined object as the + first value. If another position is wanted, use a lambda. + + ``.on`` Applies a method on the object. The method name needs to + be passed as a string due to how python works. + """ + + object: Any + + def on(self, proc: str, *args) -> 'Pipeline': + """Apply function to pipeline.""" + return Pipeline(getattr(self.object, proc)(*args)) + + def do(self, proc: Callable, *args) -> 'Pipeline': + """Run method in pipeline.""" + return Pipeline(proc(self.object, *args)) + + +with open(os.path.expanduser('~/.ssh/id_rsa'), 'rb') as f: + data = f.read() + +Pipeline(data) \ + .on('split', b'\n') \ + .do(lambda x: x[1:-2]) \ + .do(lambda d: b''.join(d)) \ + .do(base64.b64decode) \ + .do(hashlib.sha256) \ + .on('digest') \ + .do(base64.b64encode) \ + .do(sys.stdout.buffer.write) + +print() +}}} diff --git a/Python.wiki b/Python.wiki index 5df7d2e..a0e3faa 100644 --- a/Python.wiki +++ b/Python.wiki @@ -1,6 +1,8 @@ %title Python -[[PEP3131]] +- [[PEP3131]] :: Handling of weird unicode characters +- [[Python Operators]] :: And operator overloading +- [[Python Pipeline]] = Properties = property diff --git a/bolt.wiki b/bolt.wiki new file mode 100644 index 0000000..6cf5d15 --- /dev/null +++ b/bolt.wiki @@ -0,0 +1,9 @@ +[[puppet]] + +{{{ +bolt command run --help +}}} + +{{{ +bolt command run whoami -t hornquist.se --private-key ~/.ssh/id_rsa +}}} diff --git a/index.wiki b/index.wiki index 675bdcd..7b3b92d 100644 --- a/index.wiki +++ b/index.wiki @@ -13,9 +13,12 @@ - [[C++]] - [[C]] - [[Common lisp]] +- [[Concourse]] (fly) +- [[Debian Packages]] - [[Debian Repo]] - [[Matlab]] - [[Matrix]] +- [[Podman]] - [[Python]] - [[Qt Translations]] - [[VHDL]] @@ -23,9 +26,9 @@ - [[Virtualization]] - [[ansible]] - [[automake]] +- [[bolt]] - [[btrfs]] - [[cmake]] -- [[Debian Packages]] - [[emacs]] - [[ffmpeg]] - [[fpga]] @@ -44,10 +47,8 @@ - [[python]] - [[sudo]] - [[systemd]] -- [[yum]] - [[wireshark]] -- [[Concourse]] (fly) -- [[Podman]] +- [[yum]] == Projekt == - [[Adafruit]] diff --git a/puppet.wiki b/puppet.wiki index 6b4e097..921acfd 100644 --- a/puppet.wiki +++ b/puppet.wiki @@ -1,3 +1,5 @@ +[[bolt]] + https://puppet.com/docs/puppet/7/lang_resources.html `puppet strings` for documentation? -- cgit v1.2.3