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 September 24, 2024 23:18
PowerShell Import-Module with .ps1 quirk.

PowerShell Import-Module with .ps1 quirk

Well, not so much a quirk - but an interesting anti-pattern I found in some (poor quality) PowerShell. Documenting the "how and why" so I can refer to it again if needed!

Example

@magnetikonline
magnetikonline / README.md
Last active June 21, 2023 00:24
FLAC -> MP3 VBR with ffmpeg

FLAC -> MP3 VBR with ffmpeg

Convert source FLAC files in a directory to MP3 VBR (around 220-260 kbps).

#!/bin/bash -e

FLAC_SRC_DIR="/path/to/flac/files"
@magnetikonline
magnetikonline / README.md
Last active April 17, 2023 11:49
Kodi media player - update video database file paths.

Kodi media player - update video database file paths

  • The Kodi databases are all SQLite3 based.
  • For Linux, the video database will be located at: ~/.kodi/userdata/Database/MyVideosXX.db, where XX is the version number. You will most likely want the highest number available for edit.

Install SQLite CLI tools, open database

$ sudo apt-get install libsqlite3-dev sqlite3
$ sqlite3 MyVideosXX.db
@magnetikonline
magnetikonline / README.md
Last active May 1, 2023 04:43
Python AWS CloudTrail parser class.

Python AWS CloudTrail parser

Python parser class for CloudTrail event archives, previously dumped to an S3 bucket. Class provides an iterator which will:

  • Scan a given directory for archive files matching the required pattern.
  • Decompress each archive in memory.
  • Parse JSON payload and return each event in turn.

Parser contained in cloudtrailparser.py, with timezone.py used as a simple datetime.tzinfo concrete class implement to provide UTC timezone.

@magnetikonline
magnetikonline / README.md
Created July 5, 2016 01:46
SSL certificate - compare modulus of certificate vs. private key for equality.

SSL certificate - compare certificate vs. private key

Or to put it another way...

Does this certificate I have actually work with this private key I have?

Where server.crt is your certificate and server.key is your private key:

$ certMod=$(openssl x509 -text -noout -modulus -in server.crt | grep "Modulus=") && \
	keyMod=$(openssl rsa -text -noout -modulus -in server.key | grep "Modulus=") && \
	[[ $certMod == $keyMod ]] && echo "Equal"
@magnetikonline
magnetikonline / example.py
Last active July 4, 2016 00:54
Fun with Python datetime timezones.
#!/usr/bin/env python
from datetime import datetime
import timezone
def main():
my_time = datetime(
year = 2016,
month = 1,
@magnetikonline
magnetikonline / README.md
Last active December 6, 2016 07:00
JavaScript OO class / object inheritance techniques.

JavaScript object inheritance techniques

Via Object.create()

function Shape(x,y) {

	this.x = x;
	this.y = y;
}
@magnetikonline
magnetikonline / README.md
Last active September 21, 2022 05:34
Node.js HTTP receiving request dump server.

Node.js HTTP receiving request dump server

HTTP server which receives requests and dumps them to a flat file.

Usage

Start HTTP server:

$ nodejs ./httprequestdump.js
@magnetikonline
magnetikonline / README.md
Last active January 24, 2023 21:06
Python - comparing JSON data structures.

Python - comparing JSON data structures

A function compare_json_data(source_data_a,source_data_b), accepting structures populated with data loaded from json.load() and comparing for equality.

Example

$ ./compare.py 
Compare JSON result is: True
@magnetikonline
magnetikonline / README.md
Last active July 5, 2023 09:18
Compile ssh2 bindings extension for PHP7.

Compile ssh2 bindings extension for PHP7

The current PHP ssh2 extension via PECL won't compile under PHP7.

Using a more recent version via PHP's GitHub we can make this work.

$ sudo apt-get install autoconf libssh2-1-dev
$ curl -LO https://github.com/php/pecl-networking-ssh2/archive/master.zip
$ unzip master.zip
$ cd pecl-networking-ssh2-master