commit 18663f24df07507f3f287e72dba7937b512788b8
parent b3fbace96b2999a748babd938f0da643f6be9365
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date: Tue, 23 Jun 2020 14:21:25 +0200
Reformat Markdown files
Diffstat:
6 files changed, 139 insertions(+), 34 deletions(-)
diff --git a/README.md b/README.md
@@ -4,10 +4,14 @@ This repository gathers some of the scripts I use.
## License
-Unless otherwise stated, the scripts are licensed under the GNU General Public License version 3 (available [here](https://www.gnu.org/licenses/gpl-3.0.html)).
+Unless otherwise stated, the scripts are licensed under the GNU General Public
+License version 3 (available [here][gpl]).
## Author
- **Oscar Benedito** - oscar@oscarbenedito.com
-*Note*: For some scripts, I have had help from other people. Co-authors are clearly stated on those files.
+*Note*: For some scripts, I have had help from other people. Co-authors are
+clearly stated on those files.
+
+[gpl]: <https://www.gnu.org/licenses/gpl-3.0.html> "The GNU General Public License v3.0"
diff --git a/atenea-updates-notifications/README.md b/atenea-updates-notifications/README.md
@@ -1,10 +1,12 @@
# Atenea Updates Notifications
-Very simple Python script to get notified when new documents are uploaded to Atenea (an instance of Moodle). Makes use of a Gotify server.
+Very simple Python script to get notified when new documents are uploaded to
+Atenea (an instance of Moodle). Makes use of a Gotify server.
## License
-The program is licensed under the GNU General Public License version 3 (available [here](https://www.gnu.org/licenses/gpl-3.0.html)).
+The program is licensed under the GNU General Public License version 3
+(available [here][gpl]).
## Authors
@@ -13,3 +15,5 @@ Alphabetically by last name.
- **Oscar Benedito** - oscar@oscarbenedito.com
- **Ernesto Lanchares** - e.lancha98@gmail.com
- **Ferran López** - flg@tuta.io
+
+[gpl]: <https://www.gnu.org/licenses/gpl-3.0.html> "The GNU General Public License v3.0"
diff --git a/git-backup/README.md b/git-backup/README.md
@@ -1,16 +1,21 @@
# Git Backup
-Very simple script to back up all the repositories the user is member of on GitLab and GitHub.
+Very simple script to back up all the repositories the user is member of on
+GitLab and GitHub.
## Prerequisites
-In order to run the program, you will need `python3` and the python libraries specified in the `requirements.txt` file. If you have `pip3` installed, you can install the libraries with the command:
+In order to run the program, you will need `python3` and the python libraries
+specified in the `requirements.txt` file. If you have `pip3` installed, you can
+install the libraries with the command:
```
pip3 install -r requirements.txt
```
-You will also need a GitLab and a GitHub access token and crete a file named `tokens.json` with the following content:
+You will also need a GitLab and a GitHub access token and crete a file named
+`tokens.json` with the following content:
+
```json
{
"gitlab.com":"<GitLab token>",
@@ -18,7 +23,8 @@ You will also need a GitLab and a GitHub access token and crete a file named `to
}
```
-Finally, you must upload your ssh key to GitLab or GitHub if you have any private or internal repositories.
+Finally, you must upload your ssh key to GitLab or GitHub if you have any
+private or internal repositories.
## Running the program
@@ -30,7 +36,10 @@ python3 git-backup.py
### Adding custom repositories
-If you want to backup repositories from which you are not a member on the currently supported hosts, or if you want to add repositories from other hosts, you can do so creating a file named `custom_directories.json` with the following structure:
+If you want to backup repositories from which you are not a member on the
+currently supported hosts, or if you want to add repositories from other hosts,
+you can do so creating a file named `custom_directories.json` with the following
+structure:
```json
[
@@ -44,17 +53,24 @@ If you want to backup repositories from which you are not a member on the curren
]
```
-You can add more than one object to the array and it will backup all of the repositories. Make sure that you upload your ssh key to the hosts in case it is needed for authentification.
+You can add more than one object to the array and it will backup all of the
+repositories. Make sure that you upload your ssh key to the hosts in case it is
+needed for authentification.
## Future updates
- - [ ] More information on the output file or the terminal: how many new repositories were added, how many have been deleted on the hosting services.
- - [ ] Manage what happens if history has changed in the hosting service.
+- [ ] More information on the output file or the terminal: how many new
+ repositories were added, how many have been deleted on the hosting
+ services.
+- [ ] Manage what happens if history has changed in the hosting service.
## License
-The program is licensed under the GNU General Public License version 3 (available [here](https://www.gnu.org/licenses/gpl-3.0.html)).
+The program is licensed under the GNU General Public License version 3
+(available [here][gpl]).
## Author
- **Oscar Benedito** - oscar@oscarbenedito.com
+
+[gpl]: <https://www.gnu.org/licenses/gpl-3.0.html> "The GNU General Public License v3.0"
diff --git a/goaccess-stats/README.md b/goaccess-stats/README.md
@@ -1,11 +1,15 @@
# GoAccess stats
-This scripts create different outputs for GoAccess to check statistics on a given website.
+This scripts create different outputs for GoAccess to check statistics on a
+given website.
## License
-The program is licensed under the GNU General Public License version 3 (available [here](https://www.gnu.org/licenses/gpl-3.0.html)).
+The program is licensed under the GNU General Public License version 3
+(available [here][gpl]).
## Author
- **Oscar Benedito** - oscar@oscarbenedito.com
+
+[gpl]: <https://www.gnu.org/licenses/gpl-3.0.html> "The GNU General Public License v3.0"
diff --git a/hex-base64-translator/README.md b/hex-base64-translator/README.md
@@ -1,15 +1,29 @@
# Hex and Base64 translator
-This script simply translates hexadecimal strings into Base64 strings (by converting them into bits and then reading the bits as Base64) and the inverse process.
+This script simply translates hexadecimal strings into Base64 strings (by
+converting them into bits and then reading the bits as Base64) and the inverse
+process.
-The goal of this program is make a password containing only characters in the Base64 alphabet and then being able to split the secret between different parties using [ssss](http://point-at-infinity.org/ssss/) (with the hexadecimal option). With this, an attacker can't get any advantage by discarding unvalid answers, since they are all valid (when running the program normally, you can get "binary" secrets or "ASCII" secrets).
+The goal of this program is make a password containing only characters in the
+Base64 alphabet and then being able to split the secret between different
+parties using [ssss][ssss] (with the hexadecimal
+option). With this, an attacker can't get any advantage by discarding unvalid
+answers, since they are all valid (when running the program normally, you can
+get "binary" secrets or "ASCII" secrets).
-All this trouble is due to the fact that I am not sure if there is a way for an attacker with some shares of the secret to avoid making a brute-force attack by knowing the implementation of ssss and anticipate binary (and therefore invalid) results.
+All this trouble is due to the fact that I am not sure if there is a way for an
+attacker with some shares of the secret to avoid making a brute-force attack by
+knowing the implementation of ssss and anticipate binary (and therefore invalid)
+results.
## License
-The program is licensed under the GNU General Public License version 3 (available [here](https://www.gnu.org/licenses/gpl-3.0.html)).
+The program is licensed under the GNU General Public License version 3
+(available [here][gpl]).
## Author
- **Oscar Benedito** - oscar@oscarbenedito.com
+
+[ssss]: <http://point-at-infinity.org/ssss/> "Shamir's Secret Sharing Scheme"
+[gpl]: <https://www.gnu.org/licenses/gpl-3.0.html> "The GNU General Public License v3.0"
diff --git a/markion/README.md b/markion/README.md
@@ -1,10 +1,17 @@
# Markion
-Markion is a Python script to allow writing literate programs using Markdown. Markion retrieves the tangled code in a file and written it to the specified files in the output directory. This README file is an example of a file that Markion can process, indeed, this file will give you Markion itself!
+
+Markion is a Python script to allow writing literate programs using Markdown.
+Markion retrieves the tangled code in a file and written it to the specified
+files in the output directory. This README file is an example of a file that
+Markion can process, indeed, this file will give you Markion itself!
## Using Markion
### Creating the input file
-To use Markion, create a Mardown file normally, and insert code snippets as you would typically with Markdown. If you want to use that code for your output files, you should use the following syntax:
+
+To use Markion, create a Mardown file normally, and insert code snippets as you
+would typically with Markdown. If you want to use that code for your output
+files, you should use the following syntax:
<pre>
```[language] block|file blockid|filename
@@ -12,22 +19,34 @@ code snippet
```
</pre>
-Specifing the language is optional (but you should put a space between the <code>```</code> and either "block" or "file"). The next word specifies wether the code is a block or it is the content of a file, and the last word represents the block ID (to include it in other snippets) or the output file name (where the code will be written) respectively. You may add comments if desired at the end of the line, both Markdown and Markion will ignore them.
+Specifing the language is optional (but you should put a space between the
+<code>```</code> and either "block" or "file"). The next word specifies wether
+the code is a block or it is the content of a file, and the last word represents
+the block ID (to include it in other snippets) or the output file name (where
+the code will be written) respectively. You may add comments if desired at the
+end of the line, both Markdown and Markion will ignore them.
### Prerequisites
+
In order to run the program, you will need Python version 3.6 or later.
### Running the program
+
To run the program, execute the file `markion.py` followed by the input file.
```
python3 markion.py file
```
-There is an addition option `--output-directory` (or `-d`) to specify an output directory and you can also run the program with `--help` (or `-h`) to get help about the program's usage.
+There is an addition option `--output-directory` (or `-d`) to specify an output
+directory and you can also run the program with `--help` (or `-h`) to get help
+about the program's usage.
## Explanation of the program
-First of all, we will make it executable, we'll write the license notice and import all the required libraries.
+
+First of all, we will make it executable, we'll write the license notice and
+import all the required libraries.
+
```python file markion.py
#!/usr/bin/env python3
[[ include license ]]
@@ -35,41 +54,65 @@ import os, sys, re, argparse
```
### Program arguments
-We will use Python's `argparse` package to deal with our program's arguments. We initialize the parser with a brief description of the program's utility.
+
+We will use Python's `argparse` package to deal with our program's arguments. We
+initialize the parser with a brief description of the program's utility.
+
```python file markion.py
parser = argparse.ArgumentParser(description='Markion is a simple scripts that retrieves tangled code from Markdown.')
```
+
One of the arguments is the name of the input file:
+
```python file markion.py
parser.add_argument('file', metavar='file', type=str, nargs=1, help='Input file.')
```
+
Another optional argument lets the user specify the output directory.
+
```python file markion.py
parser.add_argument('-d', '--output-directory', dest='out_dir', type=str, default=os.getcwd(), help='Change the output directory.')
```
-The other argument is also optional and it lets the program automatically detect the output directory (based on the file's directory). This option will override the `--output-directory` option.
+
+The other argument is also optional and it lets the program automatically detect
+the output directory (based on the file's directory). This option will override
+the `--output-directory` option.
+
```python file markion.py
parser.add_argument('-D', '--auto-directory', dest='auto_dir', action='store_true', help='Auto detect output directory.')
```
-To calculate the directory automatically, we simply check the input file's directory.
+
+To calculate the directory automatically, we simply check the input file's
+directory.
+
```python block auto_dir
if args.auto_dir:
args.out_dir = os.path.dirname(args.file[0])
```
-Finally we assign the arguments' values to the `args` variable to use it later on.
+
+Finally we assign the arguments' values to the `args` variable to use it later
+on.
+
```python file markion.py
args = parser.parse_args()
```
### Reading the input file
+
We read the input file and copy the contents to a variable `inp`.
+
```python file markion.py
with open(args.file[0], 'r') as f:
inp = f.read()
```
### Extracting the tangled code
-We extract the important pieces of code from the `inp` variable. To do so there are two regular expressions, one that matches the blocks and one that matches the content to output in the files. We get all the snippets and save them into the variables `blocks` and `files`.
+
+We extract the important pieces of code from the `inp` variable. To do so there
+are two regular expressions, one that matches the blocks and one that matches
+the content to output in the files. We get all the snippets and save them into
+the variables `blocks` and `files`.
+
```python file markion.py
r_block = '```[\w\-.]*\s+block\s+([\w.-]+).*?\n(.*?)\n```\s*?\n'
r_file = '```[\w\-.]*\s+file\s+([\w.-]+).*?\n(.*?\n)```\s*?\n'
@@ -78,7 +121,10 @@ files = re.findall(r_file, inp, flags = re.DOTALL)
```
### Resolving includes in the tangled code
-For each file specified in the input, we resolve all the blocks that are included (recursively). To do so we use the function `resolve`.
+
+For each file specified in the input, we resolve all the blocks that are
+included (recursively). To do so we use the function `resolve`.
+
```python file markion.py
[[ include resolve ]]
block_content = { b[0] : [False, b[1]] for b in blocks }
@@ -88,7 +134,11 @@ for f in files:
file_content[f[0]] = ''
file_content[f[0]] += resolve(f[1], block_content)
```
-The following code is the function resolve included in the last code fragment, it won't be directly written on the file, but be included when the `[[ include resolve ]]` is called. As you can see it indents the whole block.
+
+The following code is the function resolve included in the last code fragment,
+it won't be directly written on the file, but be included when the
+`[[ include resolve ]]` is called. As you can see it indents the whole block.
+
```python block resolve
r_include = re.compile('([ \t]*)\[\[\s*include\s+([\w\-.]+)\s*\]\]', flags = re.DOTALL)
def resolve(content, blocks):
@@ -107,13 +157,20 @@ def resolve(content, blocks):
```
### Writing the output to the corresponding files
-Finally, if there weren't any errors, we write the output code into the respective files. To do so, we assign the directory automatically if the option has been delcared, otherwise, we create the output directory if not already created:
+
+Finally, if there weren't any errors, we write the output code into the
+respective files. To do so, we assign the directory automatically if the option
+has been delcared, otherwise, we create the output directory if not already
+created:
+
```python file markion.py
[[ include auto_dir ]]
if not os.path.exists(args.out_dir):
os.mkdirs(args.out_dir)
```
+
And we write the output.
+
```python file markion.py
for fn, fc in file_content.items():
with open(args.out_dir + '/' + fn, 'w') as f:
@@ -121,9 +178,13 @@ for fn, fc in file_content.items():
```
## License
-The program is licensed under the GNU General Public License version 3 (available [here](https://www.gnu.org/licenses/gpl-3.0.html)).
-In order to make sure there is no missunderstanding, we will include the following license notice on our file.
+The program is licensed under the GNU General Public License version 3
+(available [here][gpl]).
+
+In order to make sure there is no missunderstanding, we will include the
+following license notice on our file.
+
```python block license
# Copyright (C) 2019 Oscar Benedito
#
@@ -146,3 +207,5 @@ In order to make sure there is no missunderstanding, we will include the followi
## Author
- **Oscar Benedito** - oscar@oscarbenedito.com
+
+[gpl]: <https://www.gnu.org/licenses/gpl-3.0.html> "The GNU General Public License v3.0"