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 April 7, 2024 23:38
Bash internal field separator (IFS) usage.

Bash internal field separator (IFS) usage

The IFS internal variable is used to determine what characters Bash defines as word/item boundaries when processing character strings. By default set to whitespace characters of space, tab, and newline.

Running the example ifs.sh, comparing the difference between the default and setting only newline as a boundary we get the following output:

/path/to/first
file
/path/to/second
@magnetikonline
magnetikonline / README.md
Last active March 18, 2025 00:46
Install Git on macOS from source.

Install Git on macOS from source

A quick n' dirty Bash script to install the following:

  • autoconf, needed by Git configure.
  • git - from source.

Tested successfully under both Intel and M1 (ARM64) based architectures.

Requires as a minimum Xcode CLI tools (no need for a full install). Can be installed via the following:

@magnetikonline
magnetikonline / README.md
Last active March 5, 2017 23:31
NetScaler rewrite action to update a cookie key value.

NetScaler rewrite action to update a cookie key value

Making a note of this because NetScalers at just awful at anything when it comes to messing with HTTP header cookie values.

So I wish to update the value of a Cookie key of mykey= to mykey=new_value. I can do so with the following rewrite action:

  • Type: REPLACE

  • Expression to choose target location: HTTP.REQ.HEADER("Cookie")

  • Expression:

@magnetikonline
magnetikonline / README.md
Last active April 30, 2025 11:11
List all Git repository objects by size.

List all Git repository objects by size

Summary

Bash script which will:

  • Iterate all commits made within a Git repository.
@magnetikonline
magnetikonline / README.md
Created February 8, 2017 00:48
Stop Python urllib2 following HTTP redirects.

Stop Python urllib2 following HTTP redirects

By default calling a URL via urllib2 will follow any 30X responses returned, often not what you want.

We can correct this behavior by adding a custom "opener" class to the urllib2 module like so:

import urllib
import urllib2
@magnetikonline
magnetikonline / README.md
Last active October 25, 2020 09:54
macOS - Install tig CLI Git repository browser tool, without need for Xcode.

Install tig CLI Git repository browser tool

Without the need for Xcode bloat (yay!).

What is tig?: https://github.com/jonas/tig

# install gcc/make/etc.
# note: this will *not* install Xcode - don't be fooled by xcode in CLI command name
$ xcode-select --install
@magnetikonline
magnetikonline / README.md
Last active March 18, 2025 17:21
Install VirtualBox 7.0/6.1/6.0/5.2/5.1 guest additions on Ubuntu server guest.

Install VirtualBox guest additions onto Ubuntu server guests

Note

The following steps have been successfully tested with Ubuntu guests of:

  • 24.04LTS
  • 22.04LTS
  • 18.04LTS
  • 16.04LTS
@magnetikonline
magnetikonline / README.md
Last active March 28, 2025 13:35
Enable LDAP over SSL (LDAPS) for Microsoft Active Directory servers.

Enable LDAP over SSL (LDAPS) for Microsoft Active Directory servers

Tip

Microsoft active directory servers by default provide LDAP connections over unencrypted connections (boo!).

The steps below will create a new self signed certificate appropriate for use with and thus enabling LDAPS for an AD server. Of course the "self-signed" portion of this guide can be swapped out with a real vendor purchased certificate if required.

Steps have been tested successfully with Windows Server 2012R2, but should work with Windows Server 2008 without modification. Requires a working OpenSSL install (ideally Linux/OSX) and (obviously) a Windows Active Directory server.

@magnetikonline
magnetikonline / README.md
Last active April 29, 2024 23:45
PowerShell execute command (.exe) with arguments safely (e.g. with spaces).

PowerShell execute command with arguments safely

In my opinion this is the best way for executing external commands from PowerShell with arguments in a safe manner - via the use of an array to hold the arguments.

Consider this one a PowerShell gem to keep in the toolbox.

Note

The example below makes use of EchoArgs.exe - a small utility that simply echoes back arguments passed to it. Utility is part of the PowerShell Community Extensions, or the exe alone can be downloaded at https://ss64.com/ps/EchoArgs.exe.

Example

@magnetikonline
magnetikonline / README.md
Last active September 12, 2018 20:48
PowerShell example to copy local files recursively to target server share with orphan cleanup.

PowerShell copy local files recursively to target server

A PowerShell script which provides the following:

  • Mount remote/target server share with given username/password credentials.
  • Copy all $SourcePath files to target share ($TargetServer / $TargetShare) recursively.
  • Finally, clean up all orphaned directories/files from target share.

Usage example

./remotecopy.ps1 `
	-SourcePath "." `