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
Created June 3, 2019 01:22
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
magnetikonline / README.md
Last active May 11, 2024 13:11
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 inability 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.

Usage

  • Log into router web UI (e.g. http://192.168.0.1).
  • From the same browser session, open the "web developer tools" pane.
@magnetikonline
magnetikonline / README.md
Created November 20, 2018 12:01
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');e.id='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
magnetikonline / example.js
Last active November 14, 2018 12:58
JavaScript asynchronous generator and iteration example.
'use strict';
async function* delayList() {
function delay(timeout) {
return new Promise((resolve,reject) => {
setTimeout(() => resolve(`dealyed for: ${timeout}ms`),timeout);
});
@magnetikonline
magnetikonline / README.md
Last active December 22, 2023 11:04
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 into address and prefix size parts.
    • Converts the address part to a 32 bit binary string.
      • Example: 192.168.0.1 becomes 11000000101010000000000000000001.
@magnetikonline
magnetikonline / README.md
Last active October 21, 2025 23:48
Gmail message retention/purge by label Google script.
@magnetikonline
magnetikonline / README.md
Last active September 8, 2025 15:25
Add user ssh-agent as daemon to Ubuntu 18.04LTS server.

Add user ssh-agent as daemon to Ubuntu 18.04LTS server

Create a new systemd user unit, which starts ssh-agent upon login to server. Will remain resident until the final session for the user has logged out.

Steps

  • Create /etc/systemd/user/ssh-agent.service.

  • Run the following commands (under your user account, not root) to install the systemd unit and start:

@magnetikonline
magnetikonline / README.md
Last active August 28, 2018 00:03
Bash shift quirks.

Bash shift quirks

When using the shift built-in, have noted this interesting behavior which I have been unable to find documentation for.

Update: the answer was right in front of me, if shift is called with a value greater than arguments available in $1 - $x then it will return with a non zero status - hence the script will halt (since I'm using set -e)!

Using the script test.sh, executed using arguments:

./test.sh apple orange banana
apple
@magnetikonline
magnetikonline / README.md
Last active September 16, 2024 14:23
CloudFormation API Gateway endpoint calling a Lambda function using proxy integration example.

CloudFormation API Gateway integration to Lambda function

Template that will create the following:

  • API Gateway:
    • Deployed as a REGIONAL endpoint.
    • Single root method, accepting POST requests only, with Lambda proxy integration to a target function.
  • In-line Python Lambda function echoing back requesting users IP address to API Gateway requests:
    • IAM role for Lambda allowing CloudWatch logs access.
    • Permissions for Lambda that allow API Gateway endpoint to successfully invoke function.
@magnetikonline
magnetikonline / README.md
Last active October 19, 2023 11:22
List AWS AMI IDs for a given marketplace product URL.

List AWS AMI IDs for a given marketplace product

Script to return AMI IDs for a given AWS region associated to a marketplace product page. Requires AWS CLI and a valid set of credentials for the aws ec2 describe-images call.

Usage

  • Browse the AWS marketplace to locate the product of interest.
  • Note the URL of the product page.
  • Execute script for the desired region: