Skip to content

Instantly share code, notes, and snippets.

View magnetikonline's full-sized avatar
💡
I have an idea!

Peter Mescalchin magnetikonline

💡
I have an idea!
View GitHub Profile
@magnetikonline
magnetikonline / randomchars.sh
Last active October 21, 2015 09:48
Generate some random characters in Bash.
#!/bin/bash
cat /dev/urandom | tr -dc A-Za-z0-9- | head -c 512
@magnetikonline
magnetikonline / README.md
Last active December 7, 2023 09:18
Semver package range definitions cheatsheet.
@magnetikonline
magnetikonline / README.md
Last active July 23, 2024 00:36
Fetch current Git commit SHA-1.

Fetch current Git commit SHA-1

Method 1

From within Git repository:

$ cd /path/to/git/repo
$ git rev-parse HEAD
c8f882b484eeb71068539fd02f04c5c2eada1c02
@magnetikonline
magnetikonline / README.md
Last active April 24, 2025 14:47
Bash string manipulation cheatsheet.

Bash string manipulation cheatsheet

Assignment
Assign value to variable if variable is not already set, value is returned.

Combine with a : no-op to discard/ignore return value.
${variable="value"}
: ${variable="value"}
@magnetikonline
magnetikonline / README.md
Last active September 26, 2022 00:13
Rsync delete orphan files from target only - no copy.

Rsync delete orphan files from target only - no copy

Calling rsync in the following way, using --existing, --ignore-existing and --delete allows the following:

  • Files at target that do not exist at source will be deleted.
  • Skipping all file copy operations from source to target.
$ rsync \
 --delete \
@magnetikonline
magnetikonline / README.md
Last active June 27, 2023 17:26
Nginx keepalive connections config example to upstream servers.

Nginx upstream HTTP keepalive config example

As per Nginx documentation, the key directives of proxy_http_version and proxy_set_header need to be set as per below:

upstream backend {
	server 127.0.0.1:8080;
	keepalive 8;
}

server {
@magnetikonline
magnetikonline / README.md
Last active June 24, 2018 13:30
Cancel Ubuntu Grub2 menu after failed boot/shutdown.

Cancel Ubuntu Grub2 menu after failed boot/shutdown

Use the following values in /etc/default/grub:

GRUB_HIDDEN_TIMEOUT=2
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0
GRUB_RECORDFAIL_TIMEOUT=2
@magnetikonline
magnetikonline / README.md
Last active June 15, 2018 22:33
Escaping token replace values for sed.

Escaping token replace values for sed

In this case replacement is passed in $1. Will replace TOKEN_NAME in given /path/to/my/templatefile.txt.

The magic is sed --regexp-extended 's/[\/&]/\\&/g' - ensures replace value is not tripped up in call to sed.

#!/bin/bash -e

tokenReplace=$1