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 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 May 21, 2025 04:27
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
@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
Last active June 12, 2025 12:09
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