Skip to content

Instantly share code, notes, and snippets.

View ngsctt's full-sized avatar

Nathan ngsctt

View GitHub Profile
@ngsctt
ngsctt / hotkey eventListener.js
Created October 29, 2019 07:25
Listen for simple hotkeys
const specialKey = navigator.userAgent.indexOf('Macintosh') != -1 ? "metaKey" : "ctrlKey";
const otherKeys = ['altGraphKey','altKey','ctrlKey','metaKey','shiftKey'].filter(k => k !== specialKey);
document.addEventListener('keydown', event => {
if (event.code === key && event[specialKey] === true && !otherKeys.some(k => event[k] === true)) {
// Do something
event.preventDefault();
}
});
@ngsctt
ngsctt / comphash.sh
Last active October 21, 2019 10:00
Bash functions to: (1) visually compare two strings, and (2) compare a string with a computed SHA/MD5 checksum
compstring () {
STR_A_IN=$1
STR_B_IN=$2
STR_A_OUT=""
STR_B_OUT=""
POINTER=""
LENGTH=${#STR_A_IN}
if [ $# -lt 2 ] || [ -z $1 ]|| [ -z $2 ]; then
echo "You must provide two strings to compare"
return 1
@ngsctt
ngsctt / bookmarklet.js
Last active May 26, 2022 10:49
How to make a bookmarklet that finds the book in a product page on Booko.com.au
(function(){
var r, l, s, a, v, i; // (1)
r = /(?:97[89])?[-\s]?[0-9]{1}[-\s]?[0-9]{3}[-\s]?[0-9]{3}[-\s]?[0-9]{2}[-\s]?[0-9X]{1/; // (2)
l = window.location.href.match(r); // (3)
s = window.getSelection().toString().match(r); // (4)
a = document.activeElement;
if (a.value) { v = a.value.slice(a.selectionStart, a.selectionEnd).match(r) } // (5)
i = ""; // (6)
if (l) { i = l[0] }
if (s) { i = s[0] }
@ngsctt
ngsctt / toggle-wifi.sh
Created April 27, 2018 07:21
Toggle WiFi power (macOS)
#!/bin/bash
if [[ $(networksetup -getairportpower en0) == *On ]]
then
networksetup -setairportpower en0 off
else
networksetup -setairportpower en0 on
fi

Keybase proof

I hereby claim:

  • I am ngsctt on github.
  • I am nathanscott (https://keybase.io/nathanscott) on keybase.
  • I have a public key ASAQjsej-Kf0IgUTzM6b3NjkVOGr66gdevswYFB_N-_hmwo

To claim this, I am signing this object:

@ngsctt
ngsctt / Email obfuscation with character entities.md
Created September 22, 2017 02:29
Using character entities to obfuscate email addresses on websites to prevent scraping, in Hugo
@ngsctt
ngsctt / Hugo email shortcode.md
Last active September 19, 2022 10:38
Shortcode to inject character-escaped emails in Hugo

Without plugins, it's difficult to use obfuscated email addresses in Hugo. Additionally, Hugo will aggressively escape anything you introduce to a template, especially if it's a href attribute.

To use a character entities obfuscation technique (eg. that of http://wbwip.com/wbw/emailencoder.html), place email.html in the layouts/shortcodes folder, and place emails.yml in the data folder.

The contact email in emails.yml is the character entity-encoded form of user@example.com. It will be the default email used if you call the email shortcode (by using {{< email >}} or {{< email contact >}} in your page content) without any parameters. You can add other emails to emails.yml and use them in the email shortcode by passing their key as a parameter, eg: {{< email newKey >}}

@ngsctt
ngsctt / export.xml
Created June 21, 2017 14:09 — forked from gmontard/export.xml
Jekyll export to Medium
---
layout: none
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wp="http://wordpress.org/export/1.2/">
<channel>
<title>{{ site.name }}</title>
<link>{{ site.url }}</link>
<description>{{ site.description | xml_escape }}</description>
<pubDate/>
@ngsctt
ngsctt / Favicon list.md
Created January 14, 2016 07:27
Which favicon sizes/files to use for maximum compatiblity

Favicon list

Working out what sizes/formats/filenames to use for favicons is confusing---especially if you're trying to support legacy browsers. There are some great lists out there, but they are often out-of-date or incomplete. So here's a new one:

Normal favicons

Place favicon.ico in root directory---include a 16x16 and 32x32 image. This will be effective for most browsers. Do not add a link to the head---browsers that can use png icons may ignore them in favour of the lower-quality ico if you do. favicon.png as a 32x32 icon for browsers that can handle png.

Touch icons

Icons for use in modern browsers (eg. Safari 8+) and mobile devices.