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 August 5, 2020 14:37
Python 2 json.dump() file-like object class for tab indenting of output file.

Python 2 json.dump() file-like object class for tab indenting of output file

Using json.dump() with Python 2, indent argument is limited to number of spaces only - no ability for tabs use.

Class JSONTabIndentFileWriter provides a file-like object which will rewrite json.dump() output indending from spaces to tabs.

@magnetikonline
magnetikonline / README.md
Created May 12, 2016 02:21
Microsoft DNS server - backup and restore AD integrated zone.

Microsoft DNS server - backup and restore AD integrated zone

Firstly, backup the existing zone to a zone file. Resulting file will always be placed in C:\Windows\system32\dns - this can't be controlled:

$ dnscmd /zoneexport myzone.com myzone-backup-file.zone

To restore the zone, firstly move our myzone-backup-file.zone file back into C:\Windows\system32\dns, then:

@magnetikonline
magnetikonline / README.md
Last active November 25, 2023 13:59
Nginx & PHP-FPM systemd services.

Nginx & PHP-FPM systemd services

A basic set of systemd units for starting Nginx and PHP-FPM daemons on system startup.

  • Ensures Nginx web server has started before the PHP-FPM process.
  • Nginx pid file placed at /run/nginx.pid.
  • PHP-FPM pid file placed at /run/php7/php-fpm.pid, PHP7 PHP-FPM config at /etc/php7.
  • Based on usage with Ubuntu 16.04LTS / 18.04LTS.

Unit files are placed in /etc/systemd/system and enabled with:

@magnetikonline
magnetikonline / README.md
Last active April 15, 2017 18:50
List active connections to Microsoft SQL Server database.

List active connections to Microsoft SQL Server database

Via the master.dbo.sysprocesses system table.

Query example

SELECT [hostname],COUNT(*)
FROM master.dbo.sysprocesses
WHERE
	([dbid] = db_id('DATABASE_NAME')) AND
	([spid] > 50)
@magnetikonline
magnetikonline / README.md
Last active June 27, 2017 03:05
Mac OS X - BSD date, converting UTC time to local time.

Mac OS X BSD date, convert UTC time to local time

  • Take a given UTC time and convert to a local time string in CCYYMMDDhhmm.SS format.
  • Offset the given time by minus 20 seconds (the -20S argument to -v).
date \
	-jf "%Y-%m-%dT%H:%M:%S %z" \
	-v -20S \
	"2016-04-11T03:26:02 +0000" \
	"+%Y%m%d%H%M.%S"
@magnetikonline
magnetikonline / urlencode.sh
Created April 10, 2016 00:28
Pure Bash urlencode function.
#!/bin/bash
function URLEncode {
local dataLength="${#1}"
local index
for ((index = 0;index < dataLength;index++)); do
local char="${1:index:1}"
case $char in

Microsoft DNS server list all records

PowerShell script to query a given Microsoft DNS server for all available primary zones and list all records defined within of types:

  • A
  • AAAA
  • CNAME
  • MX
  • NS
  • PTR
  • TXT
@magnetikonline
magnetikonline / README.md
Last active February 14, 2023 23:42
AWS clone VPC route table and routes.

AWS clone VPC route table and routes

Python script to clone an existing VPC route table. Script output is a series of AWS CLI calls to create the route table and assign routes.

Update AWS_TARGET_REGION and SOURCE_ROUTE_TABLE_ID to suit.

Note: does not currently support NAT Gateways routes due to Boto 2 API limitation.

Example

@magnetikonline
magnetikonline / example.ps1
Created December 15, 2015 06:03
Creating a PowerShell PSCredential object with username/password using secure/encrypted strings.
Set-StrictMode -Version Latest
$PASSWORD = "mypassword"
# create secure string from plain-text string
$secureString = ConvertTo-SecureString -AsPlainText -Force -String $PASSWORD
Write-Host "Secure string:",$secureString
Write-Host
@magnetikonline
magnetikonline / example.ps1
Last active February 13, 2021 01:09
PowerShell push message to Slack incoming webhook.
Set-StrictMode -Version Latest
$payload = @{
"channel" = "#my-channel"
"icon_emoji" = ":bomb:"
"text" = "This is my message. Hello there!"
"username" = "Mr. Robot"
}
Invoke-WebRequest `