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 / README.md
Last active July 18, 2025 02:34
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.
  • Skip all file copy operations from source to target.
$ rsync \
 --delete \
@magnetikonline
magnetikonline / README.md
Last active September 17, 2025 23:28
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;
}
@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
@magnetikonline
magnetikonline / corstest.sh
Last active August 9, 2018 13:58
Simulate CORS GET web requests using curl.
#!/bin/bash -e
LINE_BREAK="======================================"
REQUEST_HEADERS="Content-Type"
REQUEST_METHOD="GET"
function exitError {
echo "Error: $1" >&2
@magnetikonline
magnetikonline / README.md
Last active December 12, 2024 14:05
BIND - delegate a sub domain for a zone.

BIND - delegate a sub domain for a zone

The scenario:

  • DNS zone myzone.com defined in BIND.
  • Authoritative name server at 123.16.123.1.
  • Subzone sub.myzone.com with an authoritative name server at 123.16.123.10.
  • Wishing to forward sub-zone to authoritative name server.

Config

@magnetikonline
magnetikonline / README.md
Last active November 10, 2024 19:59
Bash getopts template.

Bash getopts template

#!/bin/bash -e

function usage {
	cat <&2

Keybase proof

I hereby claim:

  • I am magnetikonline on github.
  • I am magnetikonline (https://keybase.io/magnetikonline) on keybase.
  • I have a public key whose fingerprint is FA4A B218 5B57 20B2 A93C C1E4 9C83 B9FB 627C 44B8

To claim this, I am signing this object:

@magnetikonline
magnetikonline / README.md
Last active June 7, 2023 20:57
AWS Elastic Beanstalk deploy user restricted IAM policy.

AWS Elastic Beanstalk deploy user restricted IAM policy

An IAM user policy document to give minimal rights for deploying an Elastic Beanstalk application.

Where:

  • REGION: AWS region.
  • ACCOUNT_ID: AWS account ID.
  • APPLICATION_NAME: Desired target Elastic Beanstalk application name(space).
  • IAM_INSTANCE_PROFILE_ROLE: The instance profile (IAM role) Elastic Beanstalk EC2 instaces will run under.
@magnetikonline
magnetikonline / script.sh
Last active August 29, 2015 14:21
Bash script to rename collection of JPG images with numeric index, ordered by date created.
#!/bin/bash
IFS=$'\n'
counter=1
for file in $(ls -1tr *.jpg); do
mv "$file" "$(printf "img_%04d.jpg" "$counter")"
counter=$(($counter + 1))
done