Skip to content

Instantly share code, notes, and snippets.


David Lochhead defmech

View GitHub Profile
defmech / copy-url-bookmarklet.js
Last active Feb 1, 2021
A bookmarklet that copies the current tab's url to the clipboard. Tested in Safari and can be triggered by keyboard shortcut if `Use ⌘-1 to ⌘-9 to switch tabs` is disabled.
View copy-url-bookmarklet.js
javascript: !(function (window, document) {
var tempTextArea = document.createElement("textarea");
const copyText = document.getSelection();
(tempTextArea.textContent = window.location.href),
defmech / set-css-var.js
Last active Jul 2, 2020
Updates a css variable with the scale of the window height related to a default height.
View set-css-var.js
const DefaultHeight = 768;
init() {
window.addEventListener('resize', e => {
defmech / debug-accessibilty.scss
Last active May 11, 2020
Using a CSS pseudo selector to visualise what an element's aria-label is set to.
View debug-accessibilty.scss
&:after {
width: 100%;
color: magenta;
font-weight: bold;
content: attr(aria-label);
position: absolute;
left: 0;
top: 0;
defmech /
Last active Feb 20, 2020 — forked from bradp/
New Mac Setup Script
echo "Creating an SSH key for you..."
ssh-keygen -t rsa
echo "Please add this public key to Github \n"
echo " \n"
read -p "Press [Enter] key after this..."
echo "Installing xcode-stuff"
xcode-select --install
defmech / activeElement.ts
Last active Dec 4, 2019
Here’s a handy snippet if you are debugging website accessibility. Logs out the element that currently has focus.
View activeElement.ts
window.addEventListener('keyup', (event: KeyboardEvent) => {
if (event.key === "Tab") {
console.log('document.activeElement', document.activeElement);


mat3 yuv2rgb = mat3(1.0, 0.0, 1.28033, 1.0, -0.21482, -0.38059, 1.0, 2.12798, 0.0);
mat3 rgb2yuv = mat3(0.2126, 0.7152, 0.0722, -0.09991, -0.33609, 0.43600, 0.615, -0.5586, -0.05639);


defmech / map.glsl
Created Oct 24, 2019 — forked from companje/map.glsl
map() function for GLSL known from Processing & openFrameworks
View map.glsl
float map(float value, float min1, float max1, float min2, float max2) {
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
defmech / applescript.txt
Created Aug 14, 2019
Automator Application to copy a directory list to clipboard.
View applescript.txt
tell application "Finder"
if exists Finder window 1 then
set currentDir to target of Finder window 1 as alias
set currentDir to desktop as alias
end if
end tell
defmech / SassMeister-input.scss
Last active May 13, 2019
Generated by
View SassMeister-input.scss
$home: #6C98C6;
$about: #98B7D7;
$contact: #F3F3F3;
$portfolio: #EF7239⁣;
$blog: #fdbc40;
home: $home,
about: $about,
defmech / copy_dir_listing_to_pasteboard.scpt
Last active Oct 9, 2018
AppleScript to copy current folder directory listing to pasteboard
View copy_dir_listing_to_pasteboard.scpt
tell application "Finder"
set currentDirPath to (target of front Finder window) as text
set folderName to name of folder currentDirPath
end tell
tell application "Terminal"
do shell script "cd " & (quoted form of POSIX path of currentDirPath) & "; ls | pbcopy"
end tell