Skip to content

Instantly share code, notes, and snippets.

View martymcguire's full-sized avatar

Marty McGuire martymcguire

View GitHub Profile
@rosemulazada
rosemulazada / script.js
Last active April 7, 2024 05:32
SCALABLE: Save form data to localStorage and auto-complete on refresh
// With the help of Jeremy Keith, I was able to create a fully scalable code sample that you can copy-paste into your project.
// It will save the user input value on blur, this includes radio buttons, checkboxes and date inputs besides regular text/number inputs.
// The only condition is that you give the form element on your page a data-attribute of data-form-topic="foo".
// This code snippet saves the data-attribute as the key to the localStorage, and the value of it will be an object with key/value pairs of the respective inputs name and value.
// Please refer to this gist somewhere in your code if you use it :)
// Happy coding!
// VARIABLE DECLARATIONS
// objects
let savedData = {};
@OrionReed
OrionReed / dom3d.js
Last active May 3, 2024 12:42
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
This gist describes the process of making a self-hosted installation
of Wordpress run with SQLite as a backing store, rather than MySQL.
This is not a step-by-step guide, and will require some degree of
comfort with your filesystem, editors, and logging. This involves
both fighting with and lying to these systems, and consequently
comes with no guarantees whatsoever.
---------------
@WolfgangSenff
WolfgangSenff / ShakeCamera2D.gd
Last active January 26, 2023 17:13
Camera shake from KidsCanCode
extends Camera2D
# Courtesy of KidsCanCode: http://kidscancode.org/godot_recipes/3.x/2d/screen_shake/ (this may change in the near future, so it may require a search)
# If you intend to use this, don't forget to turn on camera rotation! And keep in mind that smaller numbers are often the most useful - huge numbers make this thing *really* shake
# 3.5.x
export var decay = 0.8 # How quickly the shaking stops [0, 1].
export var max_offset = Vector2(100, 75) # Maximum hor/ver shake in pixels.
export var max_roll = 0.1 # Maximum rotation in radians (use sparingly).
export (NodePath) var target # Assign the node this camera will follow.
@adactio
adactio / previewImageUploads.js
Created May 12, 2022 13:33
Show inline previews of images that are going to be uploaded.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function (win,doc) {
'use strict';
if (!win.FileReader || !win.addEventListener || !doc.querySelectorAll) {
// doesn't cut the mustard.
return;
}
doc.querySelectorAll('input[type="file"][accept="image/*"]').forEach( function (fileInput) {
// Core assets
let coreAssets = [];
// On install, cache core assets
self.addEventListener('install', function (event) {
// Cache core assets
event.waitUntil(caches.open('app').then(function (cache) {
for (let asset of coreAssets) {
cache.add(new Request(asset));
@Arty2
Arty2 / fixedsearch.js
Last active December 14, 2023 17:10 — forked from cmod/hugofastsearch.md
Super fast, client side search for Hugo.io with Fusejs.io
// static/scripts/fixedsearch/fixedsearch.js
/*--------------------------------------------------------------
fixedsearch — Super fast, client side search for Hugo.io with Fusejs.io
based on https://gist.github.com/cmod/5410eae147e4318164258742dd053993
--------------------------------------------------------------*/
if (typeof variable !== 'undefined') {
console.log('fixedsearch.js already loaded');
} else {
fixedsearch = function(){
@dglaude
dglaude / code.py
Last active October 22, 2022 08:36
Change the MagTag program you want to run at startup.
# This file should be saved as code.py
# At MagTag startup (or at wakeup time), keep one one of the 4 button pressed.
# The MagTag will switch to the program you choose and remember that decision at each wakeup.
# The trick is to have for each button one CircuitPython program to import.
# You can customise the app_to_start list, here is the current setting:
# no button => magtag_weather
# 1 (D15) => magtag_showtimes
# 2 (D14) => magtag_tree
# 3 (D12) => magtag_spacex
# 4 (D11) => magtag_year_progress_percent
@Zegnat
Zegnat / yt.html
Last active November 8, 2020 19:55
I keep forgetting how I can do sleek YouTube embeds. Here is one from a project. Still tweaking.
<!--
Embedded Youtube player that combines:
* https://jameshfisher.com/2017/08/30/how-do-i-make-a-full-width-iframe/
* https://css-tricks.com/lazy-load-embedded-youtube-videos/
* https://stackoverflow.com/a/42555610/3225372
* https://web.dev/iframe-lazy-loading/
* https://github.com/paulirish/lite-youtube-embed/blob/a927d63781883088c185cb69a0baade52732ab3e/src/lite-yt-embed.js#L28
Other things I am still thinking of adding:
* https://www.maxlaumeister.com/articles/hide-related-videos-in-youtube-embeds/
-->
@adactio
adactio / saveTextarea.js
Last active December 2, 2023 06:52
Put the contents of a textarea into localStorage if the user leaves the page before submitting the form.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function (win, doc) {
// Cut the mustard.
if (!win.localStorage) return;
// You should probably use a more specific selector than this.
var textarea = doc.querySelector('textarea');
// The key for the key/value pair in localStorage is the current URL.
var key = win.location.href;