Skip to content

Instantly share code, notes, and snippets.

View defmech's full-sized avatar

David Lochhead defmech

View GitHub Profile
@defmech
defmech / GLSL-color.md
Created October 24, 2019 14:42 — forked from patriciogonzalezvivo/GLSL-color.md
GLSL color functions

RGB - YUB

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);

RGB - HSV

@defmech
defmech / activeElement.ts
Last active December 4, 2019 14:35
Here’s a handy snippet if you are debugging website accessibility. Logs out the element that currently has focus.
window.addEventListener('keyup', (event: KeyboardEvent) => {
if (event.key === "Tab") {
console.log('document.activeElement', document.activeElement);
}
});
@defmech
defmech / setup.sh
Last active February 20, 2020 11:19 — forked from bradp/setup.sh
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 "https://github.com/account/ssh \n"
read -p "Press [Enter] key after this..."
echo "Installing xcode-stuff"
xcode-select --install
@defmech
defmech / debug-accessibilty.scss
Last active May 11, 2020 11:03
Using a CSS pseudo selector to visualise what an element's aria-label is set to.
&:after {
width: 100%;
color: magenta;
font-weight: bold;
content: attr(aria-label);
position: absolute;
left: 0;
top: 0;
}
@defmech
defmech / set-css-var.js
Last active July 2, 2020 10:00
Updates a css variable with the scale of the window height related to a default height.
const DefaultHeight = 768;
init() {
this.updateRootCSSScale();
window.addEventListener('resize', e => {
this.updateRootCSSScale();
});
}
@defmech
defmech / copy-url-bookmarklet.js
Last active February 1, 2021 14:54
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.
javascript: !(function (window, document) {
var tempTextArea = document.createElement("textarea");
const copyText = document.getSelection();
(tempTextArea.textContent = window.location.href),
document.body.appendChild(tempTextArea),
copyText.removeAllRanges(),
tempTextArea.select(),
document.execCommand("copy"),
copyText.removeAllRanges(),
@defmech
defmech / go2shell_iTerm2.scpt
Created January 24, 2022 20:01
AppleScript version of Go2Shell
tell application "Finder"
set pathList to (quoted form of POSIX path of (folder of the front window as alias))
end tell
tell application "System Events"
if not (exists (processes where name is "iTerm2")) then
do shell script "open -a iTerm " & pathList
else
tell application "iTerm"
set newWindow to (create window with default profile)
@defmech
defmech / copy_dir_list.scpt
Created January 24, 2022 20:17
Copies directory listing, of front Finder window, to clipboard.
tell application "Finder"
set pathList to (quoted form of POSIX path of (folder of the front window as alias))
end tell
tell application "Terminal"
do shell script "cd " & pathList & "; ls | pbcopy"
end tell