Skip to content

Instantly share code, notes, and snippets.

extended working from home...

Peter Mescalchin magnetikonline

extended working from home...
View GitHub Profile
magnetikonline /
Last active May 2, 2020
Golang io.TeeReader() example.

Golang io.TeeReader() example

  • Opening a source words file.
  • Create a io.TeeReader(), writing read file chunks also to a gzip writer.
  • Output source chunks as read and total bytes.
  • Finally, output compressed bytes and total compressed size.


$ go run main.go
magnetikonline /
Created Feb 4, 2020
GitHub token validation regular expressions.

GitHub token validation regular expressions

Simple regular expressions to check if a given GitHub token could be valid.

Personal access tokens

Personal access tokens are exactly 40 hexadecimal characters in length.

magnetikonline /
Last active Oct 15, 2019
VirtualBox create host-only interface and attached to VM.
magnetikonline /
Created Jun 3, 2019
Git correct a commit via --fixup

Git correct a commit via --fixup

Initial commit state:

$ git log --oneline
733e2ff Second widget done
fb2f677 First widget done
ac5db87 First commit
magnetikonline /
Last active Aug 20, 2019
Modify DHCP DNS servers for Optus supplied (Vividwireless) Huawei B315 4G modem.

Modify DNS for Optus supplied Huawei B315 4G modem

The Huawei B315 modem supplied by Optus for the (now defunt) Vividwireless service is a workable but sadly rather crippled device, even down to the inabiilty to modify assigned DNS servers from it's DHCP server away from Optus DNS to something sane (Google DNS/Cloudflare/etc.).

This script should allow for the easy update of assigned DNS servers and has been tested with Google Chrome.


  • Log into router web UI (e.g.
  • From the same browser session, open the "web developer tools" pane.
  • Drop the contents of dnsmodify.js into Console area - modifying ROUTER_URI, PRIMARY_DNS and SECONDARY_DNS to suit.
  • Run the script, updated DHCP settings are pushed and modem will restart.
magnetikonline /
Created Nov 20, 2018
GitHub pull request timeline toggle "force-pushed" events bookmarklet.

GitHub pull request toggle "force-pushed" events bookmarklet

Since November 2018, GitHub have started to display forced push events to pull request page timelines. This bookmarklet will toggle display of these events if they are getting in the way of meaningful commits.

Add the code below as the URL of a new bookmark:

javascript:((d)=>{if(d.getElementById('nuke-fp')==null){let e=d.createElement('style');'nuke-fp';e.innerHTML='.nuke-fp{display:none}';d.getElementsByTagName('head')[0].appendChild(e)}for(let e of Array.from(d.querySelectorAll('.discussion-timeline .discussion-item-head_ref_force_pushed'))){e.classList.toggle('nuke-fp')}})(document)

Tested with Chrome 70.0.3538.102.

magnetikonline / example.js
Last active Nov 14, 2018
JavaScript asynchronous generator and iteration example.
View example.js
'use strict';
async function* delayList() {
function delay(timeout) {
return new Promise((resolve,reject) => {
setTimeout(() => resolve(`dealyed for: ${timeout}ms`),timeout);
magnetikonline /
Last active Oct 12, 2019
Python function to determine if a given IPv4 CIDR "fits" into another.

CIDR fit

Python function to determine if a given IPv4 CIDR fits into another.

How cidr_fit(cidr_a,cidr_b) works:

  • For both CIDR's given:
    • Splits each CIDR in address and prefix size parts.
    • Converts the address part to a 32 bit binary string.
      • E.g. becomes 11000000101010000000000000000001.
    • Cuts out everything after the prefix size.
      • E.g. becomes 110000001010.
magnetikonline /
Last active Mar 10, 2020
Gmail message retention/purge by label Google script.

Gmail retention/purge by label Google script

A Google Apps Script which adds pseudo message retention-like policies against specific labels for a Gmail account.

How it works

  • Apps Script function is called automatically on a regular schedule.
  • Script iterates over a set of predefined message labels.
You can’t perform that action at this time.