Skip to content

Instantly share code, notes, and snippets.

View crates's full-sized avatar
❤️‍🔥
Crates is CEO of llnnll.com, Athames.com, Crates.Media / Cr8s.Net : 844-CR8S-NET

Crates McDade crates

❤️‍🔥
Crates is CEO of llnnll.com, Athames.com, Crates.Media / Cr8s.Net : 844-CR8S-NET
View GitHub Profile
@crates
crates / async-parallel.js
Last active May 31, 2018 17:35
Parallel, asynchronous AJAX calls in ES6
const parallel = async (...items) => {
const temp = [];
for (const item of items) {
temp.push(await item);
}
return temp;
};
const finalResult = await parallel(someResult(), anotherResult());
//or
@crates
crates / exit-modal.js
Created June 28, 2018 19:49
Exit Modal: fires an exit modal when the user seeks to leave the page
(function($, Drupal) {
"use strict";
var exitModalCookie = $.cookie("__exitModal");
// set up exit intent listener to fire modal
var exitIntent = function(e) {
if (e.clientY < 0 ) {
// init remodal
var exitModal = $('[data-remodal-id=exit-modal]').remodal();
exitModal.open();
// prevent sowing this more than once per page
data:text/html, <html contenteditable><body style="font-family:menlo, 'lucida console', 'courier new', monospace; margin:20px;border:solid 1px #ccc; padding: 10px;">
@crates
crates / Edit Page Bookmark.txt
Created July 16, 2018 17:22
Edit This Page (put this into a bookmark to make any page editable)
javascript:document.body.contentEditable = 'true'; document.designMode='on'; void 0
@crates
crates / HarlemShake.js
Created July 16, 2018 17:24
Harlem Shake Bookmark: Run this on any page to do the Harlem Shake
javascript:(function(){function c(){var e=document.createElement("link");e.setAttribute("type","text/css");e.setAttribute("rel","stylesheet");e.setAttribute("href",f);e.setAttribute("class",l);document.body.appendChild(e)}function h(){var e=document.getElementsByClassName(l);for(var t=0;t<e.length;t++){document.body.removeChild(e[t])}}function p(){var e=document.createElement("div");e.setAttribute("class",a);document.body.appendChild(e);setTimeout(function(){document.body.removeChild(e)},100)}function d(e){return{height:e.offsetHeight,width:e.offsetWidth}}function v(i){var s=d(i);return s.height>e&&s.height<n&&s.width>t&&s.width<r}function m(e){var t=e;var n=0;while(!!t){n+=t.offsetTop;t=t.offsetParent}return n}function g(){var e=document.documentElement;if(!!window.innerWidth){return window.innerHeight}else if(e&&!isNaN(e.clientHeight)){return e.clientHeight}return 0}function y(){if(window.pageYOffset){return window.pageYOffset}return Math.max(document.documentElement.scrollTop,document.body.scrollTop)}funct
@crates
crates / getQueryStrAsObj
Created January 30, 2019 15:22
Gets the current site's query string and returns it as a JavaScript object
const getQueryStrAsObj = () => {
const paramsToObject = (keys) => { let result = {}; for(let entry of keys) result[entry[0]] = entry[1]; return result };
const params = new URLSearchParams(location.search.substr(1, location.search.length - 1));
return paramsToObject(params.entries());
};
@crates
crates / concurrent-async.js
Last active September 18, 2019 20:25
A demonstration of 3 methods running asynchronously with promises
function sleep(ms) {
return new Promise(resolve => {
console.log(`starting ${ms}`);
setTimeout(() => {
console.log(`done ${ms}`);
resolve(ms);
}, ms);
});
}
@crates
crates / gitAliases.sh
Created February 15, 2019 18:42
A list of the git alias commands I use on every system
#!/bin/sh
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.hist "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"
git config --global alias.type 'cat-file -t'
git config --global alias.dump 'cat-file -p'
@crates
crates / browser-notes.txt
Last active April 29, 2019 18:00
In-browser Notes: Take notes using a browser bookmark
data:text/html;charset=utf-8,<title>In-Browser Text Editor</title><style>body%7Bbackground%3A%23123%3Bcolor%3A%23333%3Bpadding%3A20px%3Bmargin%3A0%2520auto%3Bwidth%3A90%25%7Dtextarea%7Bbackground%3A%23fbfbfb%3Bborder%3A0%3Bcolor%3A%23333%3Bfont-family%3Asans-serif%3Bfont-size%3A2rem%3Bheight%3A98%25%3Bline-height%3A1.4%3Bmargin%3A0%2520auto%3Boutline%3A0%3Bpadding%3A4rem%3Bwidth%3A100%25%7Dbutton%7Bbackground-color%3A%23fbfbfb%3Bborder%3A1px%2520%23ccc%2520solid%3Bcolor%3A%23999%3Bcursor%3Apointer%3Bfloat%3Aright%3Bmargin%3A10px%25200%3Bpadding%3A5px%252010px%7D%40media%2520%28max-width%3A768px%29%7Bbody%7Bwidth%3A100%25%3Bpadding%3A0%7Dtextarea%7Bpadding%3A10px%7Dbutton%7Bfloat%3Anone%7D%7D</style><body><button%20onclick="sM();%20return%20false">Email%20this</button><textarea%20contenteditable%20id=TE%20spellcheck=false%20placeholder=Write...%20autofocus></textarea><script>function%20sM(){var d=new Date();var t=d.toDateString()+' '+d.toLocaleTimeString();var%20a="mailto:[email protected]?subject="+escape("In
@crates
crates / Drupal-Exit-Modal.js
Created April 2, 2019 17:27
Drupal / jQuery Exit Modal: Show the user a modal when they are attempting to leave your website
(function($, Drupal) {
"use strict";
var exitModalCookie = $.cookie("__exitModal");
// set up exit intent listener to fire modal
var exitIntent = function(e) {
if (e.clientY < 0 ) {
// init remodal
var exitModal = $('[data-remodal-id=exit-modal]').remodal();
exitModal.open();
// prevent sowing this more than once per page