Skip to content

Instantly share code, notes, and snippets.

@captain-proton
captain-proton / eval_user_presence.yml
Created September 19, 2024 07:12
Ansible playbook to evaluate the existence of a user
- name: Evaluate user presence
hosts: all
become: true
vars:
__username: "{{ username | default(None) }}"
tasks:
- name: Check if username is set
connection: local
@captain-proton
captain-proton / validate_users.yml
Last active March 13, 2024 12:23
Ansible playbook to validate standard user accounts
---
- name: Validate standard users users
hosts: all
become: true
gather_facts: false
vars:
users:
- myuser

This short script creates a virtual environment for python if it does not exist yet. The second step is to activate the environment. The script must be executed via source ..., even if the current shell has the command! Otherwise the virtual environment is not activated. As so often there is on stackoverflow the appropriate answer.

alias venv='source $HOME/.local/bin/python_venv.sh'

Afterwards the command can be executed in any directory where a virtual environment should exist.

$ venv
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

In the case that a certificate for a specific url should be created and there is a person or department, that is responsible to sign the certificate request the following procedure can be used. First of all a certificate signing request (CSR) is needed. As the certificate is bound to a private key to use it afterwards, the request and key are stored.

openssl req -newkey rsa:2048 -keyout key.pem -out request.csr -subj '/C=DE/ST=<your State>/L=<your Location/O=<your company>/CN=<server url>' -sha256

The parameter -sha256 is important. By default openssl uses SHA1 as signature algorithm. SHA1 is no longer supported by the majority of all browsers. The signing request can be checked with

openssl req -in request.csr -noout -text | grep Signature

There should be an output like

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@captain-proton
captain-proton / ISBN.java
Last active August 16, 2021 14:20
Validate ISBN-10 and ISBN-13 numbers by several properties
/**
* An <code>ISBN</code> can be used to validate ISBN numbers of type 10 and 13. The validation is focused on the
* numbers and hyphens of a ISBN. Therefore be sure to check that all other characters are removed before validation.
* After validation is done, a validation result can be retrieved to check which property was invalid.
*
* @see <a href="https://en.wikipedia.org/wiki/International_Standard_Book_Number">International Standard Book Number on Wikipedia</a>
* @see ValidationProperty
*/
public class ISBN {
package concurrency;
import java.util.stream.Stream;
/**
* The <code>Synchronization</code> is meant to show that a synchronization block on class objects taken from
* <code>Object.class</code> differs from the use of single objects (<code>new Object()</code>).
*/
public class Synchronization
{