aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-06-25 06:41:04 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-06-25 06:41:04 +0200
commit3af714e89059739f365c3a92c8833864665ff497 (patch)
tree6c64dea8648cf7e81a437a0c9aa9678988d258c0
parentlör 24 jun 2023 17:53:25 CEST (diff)
downloadwiki-public-3af714e89059739f365c3a92c8833864665ff497.tar.gz
wiki-public-3af714e89059739f365c3a92c8833864665ff497.tar.xz
sön 25 jun 2023 06:41:04 CEST
-rw-r--r--Python Operators.wiki39
-rw-r--r--Python Pipeline.wiki56
-rw-r--r--Python.wiki4
-rw-r--r--bolt.wiki9
-rw-r--r--index.wiki9
-rw-r--r--puppet.wiki2
6 files changed, 114 insertions, 5 deletions
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?