From b4071ec6608f26e47ac41ec027a53fc444fab023 Mon Sep 17 00:00:00 2001 From: samuel Date: Fri, 22 May 2020 16:35:56 +0200 Subject: [PATCH] pushing using magit yay --- sami/learn-python-the-hard-way/#ex1.py# | 8 ++++ sami/learn-python-the-hard-way/.#ex1.py | 1 + sami/learn-python-the-hard-way/ex15.py | 18 ++++++++ sami/learn-python-the-hard-way/ex16.py | 41 +++++++++++++++++ sami/learn-python-the-hard-way/ex17.py | 28 +++++++++++ sami/learn-python-the-hard-way/ex18.py | 25 ++++++++++ sami/learn-python-the-hard-way/ex19.py | 26 +++++++++++ sami/learn-python-the-hard-way/ex20.py | 46 +++++++++++++++++++ sami/learn-python-the-hard-way/ex21.py | 39 ++++++++++++++++ sami/learn-python-the-hard-way/ex22.py | 5 ++ sami/my-org-files/cdist.org/#all-in-one# | 43 +++++++++++++++++ sami/my-org-files/cdist.org/all-in-one.org | 42 +++++++++++++++++ .../cdist.org/cdist#3-requirements.org | 33 +++++++++++++ ...st#5-messsaging => cdist#5-messsaging.org} | 0 14 files changed, 355 insertions(+) create mode 100644 sami/learn-python-the-hard-way/#ex1.py# create mode 120000 sami/learn-python-the-hard-way/.#ex1.py create mode 100644 sami/learn-python-the-hard-way/ex15.py create mode 100644 sami/learn-python-the-hard-way/ex16.py create mode 100644 sami/learn-python-the-hard-way/ex17.py create mode 100644 sami/learn-python-the-hard-way/ex18.py create mode 100644 sami/learn-python-the-hard-way/ex19.py create mode 100644 sami/learn-python-the-hard-way/ex20.py create mode 100644 sami/learn-python-the-hard-way/ex21.py create mode 100644 sami/learn-python-the-hard-way/ex22.py create mode 100644 sami/my-org-files/cdist.org/#all-in-one# create mode 100644 sami/my-org-files/cdist.org/all-in-one.org create mode 100644 sami/my-org-files/cdist.org/cdist#3-requirements.org rename sami/my-org-files/cdist.org/{cdist#5-messsaging => cdist#5-messsaging.org} (100%) diff --git a/sami/learn-python-the-hard-way/#ex1.py# b/sami/learn-python-the-hard-way/#ex1.py# new file mode 100644 index 0000000..04e1500 --- /dev/null +++ b/sami/learn-python-the-hard-way/#ex1.py# @@ -0,0 +1,8 @@ +n +print("Hello World!") +print("Hello Again") +print("I like typing this.") +print("This is fun.") +print('Yay! Printing.') +print("I'd much rather you 'not'.") +print('I "said" do not touch this.') diff --git a/sami/learn-python-the-hard-way/.#ex1.py b/sami/learn-python-the-hard-way/.#ex1.py new file mode 120000 index 0000000..60f2e79 --- /dev/null +++ b/sami/learn-python-the-hard-way/.#ex1.py @@ -0,0 +1 @@ +sami@afro-linux-lenovo-b50-30.19806:1589891645 \ No newline at end of file diff --git a/sami/learn-python-the-hard-way/ex15.py b/sami/learn-python-the-hard-way/ex15.py new file mode 100644 index 0000000..5539d4b --- /dev/null +++ b/sami/learn-python-the-hard-way/ex15.py @@ -0,0 +1,18 @@ +from sys import argv + +script, filename = argv + + +txt = open(filename) + +print(f"Here's your file {filename}:") +print(txt.read()) + +print("Type the filename again:") +file_again = input("> ") + + +txt_again = open(file_again) + + +print(txt_again.read()) diff --git a/sami/learn-python-the-hard-way/ex16.py b/sami/learn-python-the-hard-way/ex16.py new file mode 100644 index 0000000..e8a2389 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex16.py @@ -0,0 +1,41 @@ + +from sys import argv + + +script, filename = argv + +print(f"We're going to erase {filename}.") +print("If you don't want that, hit CTRL-C (^C).") +print("If you do want that, hit RETURN.") + + +input("?") + +print("Opening the file...") +target = open(filename, 'w') + +print("Truncating the file. +target.truncate() + +Goodbye!") + + +print("Now I'm going to ask you for three lines.") + +line1 = input("line 1: ") +line2 = input("line 2: ") +line3 = input("line 3: ") + + +print("I'm going to write these to the file.") + +target.write(line1) +target.write("\n") +target.write(line2) +target.write("\n") +target.write(line3) +target.write("\n") + +print("And finally, we close it.") + +target.close() diff --git a/sami/learn-python-the-hard-way/ex17.py b/sami/learn-python-the-hard-way/ex17.py new file mode 100644 index 0000000..c6a0f1f --- /dev/null +++ b/sami/learn-python-the-hard-way/ex17.py @@ -0,0 +1,28 @@ +from sys import argv +from os.path import exists + + +script, from_file, to_file = argv + + +print(f"Copying from {from_file} to {to_file}") + +# we could do these two on one line, how? +in_file = open(from_file) + +indata = in_file.read() + + +print(f"The input file is {len(indata)} bytes long") + +print(f"Does the output file exist? {exists(to_file)}") +print("Ready, hit RETURN to continue, CTRL-C to abort.") +input() + +out_file = open(to_file, 'w') +out_file.write(indata) + +print("Alright, all done.") + +out_file.close() +in_file.close() diff --git a/sami/learn-python-the-hard-way/ex18.py b/sami/learn-python-the-hard-way/ex18.py new file mode 100644 index 0000000..b9617a4 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex18.py @@ -0,0 +1,25 @@ +# this one is like your scripts with argv +def print_two(*args): +arg1, arg2 = args +print(f"arg1: {arg1}, arg2: {arg2}") + +# ok, that *args is actually pointless, we can just do this +def print_two_again(arg1, arg2): + +print(f"arg1: {arg1}, arg2: {arg2}") + +# this just takes one argument +def print_one(arg1): + +print(f"arg1: {arg1}") + +# this one takes no arguments +def print_none(): + +print("I got nothin'.") + + +print_two("Zed","Shaw") +print_two_again("Zed","Shaw") +print_one("First!") +print_none() diff --git a/sami/learn-python-the-hard-way/ex19.py b/sami/learn-python-the-hard-way/ex19.py new file mode 100644 index 0000000..a8f60d6 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex19.py @@ -0,0 +1,26 @@ +def cheese_and_crackers(cheese_count, boxes_of_crackers): +print(f"You have {cheese_count} cheeses!") +print(f"You have {boxes_of_crackers} boxes of crackers!") +print("Man that's enough for a party!") +print("Get a blanket.\n") + + +print("We can just give the function numbers directly:") +cheese_and_crackers(20, 30) + + +print("OR, we can use variables from our script:") +amount_of_cheese = 10 +amount_of_crackers = 50 + + +cheese_and_crackers(amount_of_cheese, amount_of_crackers) + + +print("We can even do math inside too:") +cheese_and_crackers(10 + 20, 5 + 6) + + +print("And we can combine the two, variables and math:") + +cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000) diff --git a/sami/learn-python-the-hard-way/ex20.py b/sami/learn-python-the-hard-way/ex20.py new file mode 100644 index 0000000..2e02b87 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex20.py @@ -0,0 +1,46 @@ +from sys import argv + + +script, input_file = argv + + + +def print_all(f): +print(f.read()) + + + +def rewind(f): +f.seek(0) + + + +def print_a_line(line_count, f): +print(line_count, f.readline()) + + +current_file = open(input_file) + + +print("First let's print the whole file:\n") + + +print_all(current_file) + + +print("Now let's rewind, kind of like a tape.") + + +rewind(current_file) + + +print("Let's print three lines:") + +current_line = 1 +print_a_line(current_line, current_file) + +current_line = current_line + 1 +print_a_line(current_line, current_file) + +current_line = current_line + 1 +print_a_line(current_line, current_file) diff --git a/sami/learn-python-the-hard-way/ex21.py b/sami/learn-python-the-hard-way/ex21.py new file mode 100644 index 0000000..fffb76a --- /dev/null +++ b/sami/learn-python-the-hard-way/ex21.py @@ -0,0 +1,39 @@ +def add(a, b): +print(f"ADDING {a} + {b}") +return a + b + + +def subtract(a, b): +print(f"SUBTRACTING {a} - {b}") +return a - b + + +def multiply(a, b): +print(f"MULTIPLYING {a} * {b}") +return a * b + + +def divide(a, b): +print(f"DIVIDING {a} / {b}") +return a / b + + +print("Let's do some math with just functions!") + +age = add(30, 5) +height = subtract(78, 4) +weight = multiply(90, 2) +iq = divide(100, 2) + + +print(f"Age: {age}, Height: {height}, Weight: {weight}, IQ: {iq}") + + +# A puzzle for the extra credit, type it in anyway. +print("Here is a puzzle.") + + +what = add(age, subtract(height, multiply(weight, divide(iq, 2)))) + + +print("That becomes: ", what, "Can you do it by hand?") diff --git a/sami/learn-python-the-hard-way/ex22.py b/sami/learn-python-the-hard-way/ex22.py new file mode 100644 index 0000000..4eceb50 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex22.py @@ -0,0 +1,5 @@ +* What Do Know SO far? + +** print : The print function in Python is a function that outputs to your console window whatever you say you want to print out. + +** diff --git a/sami/my-org-files/cdist.org/#all-in-one# b/sami/my-org-files/cdist.org/#all-in-one# new file mode 100644 index 0000000..a9c3f85 --- /dev/null +++ b/sami/my-org-files/cdist.org/#all-in-one# @@ -0,0 +1,43 @@ +*** cdist #6: Glueing it together +**** Lecture content +***** Objective + - Apply learnings from the previous cdist sessions +***** Steps 1: *__all_in_one* (1.25h) + - Create a new type named *__all_in_one* + - Decide yourself whether it is a singleton or not + - Reason why in your cdist.org file + - It should work on alpine, debian and fedora + - It accepts the following parameters: + - *--with-x* (boolean) + - *--extra-packages* (optional multiple) + - On Alpine, it should install netcat-openbsd and tshark + - On Debian, it should install netcat tshark + - On Fedora, it should install nmap-ncat wireshark-cli + - On all operating systems install socat sipcalc sudo + - If the detected operating system is neither + Alpine/Debian/Fedora, output an error message and abort the + manifest with exit code 1 + - Additionally install all packages specified by the *--extra-packages* parameter +***** Steps 2: *__firewall* (1.25h) + - Create a new type *__my_firewall* + - Add a *type explorer* to find out whether nft is present on + the target system + - Add a required parameter named *file* + - If the type explorer does not detect nft on the target system, + abort with an error message + - Deploy the specified file to */etc/my-nftables* + - Add a *type explorer* that reads the current nft rules + - If the rules are different on the target host, apply the new + ruleset by generating code in *gencode-remote* + - If the filename specified by the *file* parameter is *-* (the + minus sign), then the type should read from *stdin* +***** Step 3: manifest (0.5h) + - Create a new manifest in the folder that contains the initial manifest + - Name the new manifest *firewall* + - Source the *firewall* manifest in the *initial* manifest + - In the *firewall* manifest, match on *localhost* + - Install nftables + - Use the *__firewall* type + - Use correct *require* parameter to ensure that nftables is + installed before the *__firewall* type is run + \ No newline at end of file diff --git a/sami/my-org-files/cdist.org/all-in-one.org b/sami/my-org-files/cdist.org/all-in-one.org new file mode 100644 index 0000000..05b2399 --- /dev/null +++ b/sami/my-org-files/cdist.org/all-in-one.org @@ -0,0 +1,42 @@ +*** cdist #6: Glueing it together +**** Lecture content +***** Objective + - Apply learnings from the previous cdist sessions +***** Steps 1: *__all_in_one* (1.25h) + - Create a new type named *__all_in_one* + - Decide yourself whether it is a singleton or not + - Reason why in your cdist.org file + - It should work on alpine, debian and fedora + - It accepts the following parameters: + - *--with-x* (boolean) + - *--extra-packages* (optional multiple) + - On Alpine, it should install netcat-openbsd and tshark + - On Debian, it should install netcat tshark + - On Fedora, it should install nmap-ncat wireshark-cli + - On all operating systems install socat sipcalc sudo + - If the detected operating system is neither + Alpine/Debian/Fedora, output an error message and abort the + manifest with exit code 1 + - Additionally install all packages specified by the *--extra-packages* parameter +***** Steps 2: *__firewall* (1.25h) + - Create a new type *__my_firewall* + - Add a *type explorer* to find out whether nft is present on + the target system + - Add a required parameter named *file* + - If the type explorer does not detect nft on the target system, + abort with an error message + - Deploy the specified file to */etc/my-nftables* + - Add a *type explorer* that reads the current nft rules + - If the rules are different on the target host, apply the new + ruleset by generating code in *gencode-remote* + - If the filename specified by the *file* parameter is *-* (the + minus sign), then the type should read from *stdin* +***** Step 3: manifest (0.5h) + - Create a new manifest in the folder that contains the initial manifest + - Name the new manifest *firewall* + - Source the *firewall* manifest in the *initial* manifest + - In the *firewall* manifest, match on *localhost* + - Install nftables + - Use the *__firewall* type + - Use correct *require* parameter to ensure that nftables is + installed before the *__firewall* type is run diff --git a/sami/my-org-files/cdist.org/cdist#3-requirements.org b/sami/my-org-files/cdist.org/cdist#3-requirements.org new file mode 100644 index 0000000..975c4c7 --- /dev/null +++ b/sami/my-org-files/cdist.org/cdist#3-requirements.org @@ -0,0 +1,33 @@ +*** cdist #3: type parameters +**** Lecture content + +***** Create a new type named *__colourful_file* + + - The objective is to create a type that creates colourful file + - The content of the file should be "colour=...", where "..." is + a colour specified by a parameter + - Add an *optional parameter* named *colour* + - Use the **__file** type inside your type to create a file + - Use the *$__object_id* variable inside your type + +***** Extend your type to be more colourful + - Modify the *optional parameter* to be able to be specified + *multiple times* + - For each time it is specified, add a line "colour=..." to the file + + +***** Create a new type *__my_dotfiles* + - Objective is to manage the dotfiles in your home directory + - Make it a *singleton* type + - Create a sub directory *files* in the type + - Add your .emacs config to the files folder + - Add a *for* loop to your type to deploy .[A-z]* to your home directory + - Add a .bashrc or .zshrc to the files folder (depending on your shell) + - In the initial manifest, add __my_dotfiles when the target + host is localhost +***** As usual commit all changes to your ungleich-learning-circle repo + + +* Defining parameters +** Every type consists of required, optional and boolean parameters, which + must each be declared in a newline separated file in parameter/required, diff --git a/sami/my-org-files/cdist.org/cdist#5-messsaging b/sami/my-org-files/cdist.org/cdist#5-messsaging.org similarity index 100% rename from sami/my-org-files/cdist.org/cdist#5-messsaging rename to sami/my-org-files/cdist.org/cdist#5-messsaging.org