Skip to content

Instantly share code, notes, and snippets.

View jgoslow's full-sized avatar

Jonas Goslow jgoslow

View GitHub Profile
@jgoslow
jgoslow / slack.reminder.snippet
Created October 5, 2022 17:01
Daily standup reminder snippet for Slack
/remind #channel “Time to post your Daily Update
Y: What you do yesterday?
T: What are you working on today?
B: Do you have any blockers?” at 10AM every weekday.
@jgoslow
jgoslow / element-is-visible
Created August 13, 2022 18:18
Element In View JS Helper Functions
/**
* Check if Element is in View
*/
function elementIsVisible(el, offset) {
const rect = el.getBoundingClientRect();
return (
rect.top < window.innerHeight && rect.bottom - offset >= 0
);
}
@jgoslow
jgoslow / copy-Input-value-to-clipboard
Created August 13, 2022 18:16
Clipboard JS Helper Functions
function copyInputValueToClipboard(input) {
input.select();
document.execCommand("copy");
console.log(`${input.value} copied to clipboard!`)
}
@jgoslow
jgoslow / get-ancestor-by-attribute.js
Created August 13, 2022 18:05
Ancestor Selection JS Helper Functions
function getAncestorByAttribute(elem, attribute) {
if (elem.parentElement === null) {
return false;
} else if (elem.hasAttribute(attribute)) {
return elem;
} else {
return getAncestorByAttribute(elem.parentElement, attribute);
}
}
@jgoslow
jgoslow / elem-unwrap.js
Created August 13, 2022 18:04
Unwrap an element from it's container
/**
* Unwrap element
*/
function unwrap(wrapper) {
// place childNodes in document fragment
var docFrag = document.createDocumentFragment();
while (wrapper.firstChild) {
var child = wrapper.removeChild(wrapper.firstChild);
docFrag.appendChild(child);
}
@jgoslow
jgoslow / throttle.js
Created August 13, 2022 18:02
Throttle and Debounce JS Functions
/**
* Debounce Function
* to reduce # of events fired
* example: Scroll listeners
*/
function debounce(callback, interval) {
let debounceTimeoutId;
return function(...args) {
clearTimeout(debounceTimeoutId);
@jgoslow
jgoslow / terminal-cors-test.js
Last active August 13, 2022 17:46
cors scripts
function corsTest(url) {
console.log("cors-test");
var http = new XMLHttpRequest();
http.open('GET', url, true);
http.onreadystatechange = function() {//Call a function when the state changes.
console.log(http.responseText)
}
@jgoslow
jgoslow / scrollbar.css
Created May 2, 2020 17:13
How to style scrollbars in CSS (May 2020)
/* Coursey of https://alligator.io/css/css-scrollbars */
/* The emerging W3C standard
that is currently Firefox-only */
* {
scrollbar-width: thin;
scrollbar-color: blue orange;
}
/* Works on Chrome/Edge/Safari */
@jgoslow
jgoslow / custom-excerpt-length.php
Last active August 13, 2022 18:09
Wordpress Excerpt PHP Functions
/**
* Filter the except length to 20 words.
*
* @param int $length Excerpt length.
* @return int (Maybe) modified excerpt length.
*/
function wpdocs_custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );
@jgoslow
jgoslow / lyra-modal-mixin.scss
Last active August 13, 2022 17:49
Lyra Modal SCSS Mixin
//Modal styles - mostly based on Bootstrap
@mixin modal() {
position: fixed;
pointer-events: none;
opacity: 0;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1050;