Skip to content

Instantly share code, notes, and snippets.

View jgoslow's full-sized avatar

Jonas Goslow jgoslow

View GitHub Profile
@jgoslow
jgoslow / permissions_ssh.bash
Last active June 9, 2016 17:45
Here are some things you can do with Gists in GistBox.
Default:
find * -type d -exec chmod 755 {} \;
find * -type f -exec chmod 644 {} \;
For Groups:
find * -type d -exec chmod 775 {} \;
find * -type f -exec chmod 664 {} \;
@jgoslow
jgoslow / Limit String Length - end of word
Last active September 29, 2018 22:42
Limits the length of a string but ensures you end on a word
// javascript word cut
function cut(n) {
return function textCutter(i, text) {
var short = text.substr(0, n);
if (/^\S/.test(text.substr(n)))
return short.replace(/\s+\S*$/, "");
return short;
};
}
@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 / 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 / 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;
@jgoslow
jgoslow / delete-cookie.js
Last active August 13, 2022 17:50
Cookie JS Functions
@jgoslow
jgoslow / scroll-to-div.jquery
Last active August 13, 2022 18:00
JS Scrolling functions
function scrollToDiv(target) {
var loc = $(target).offset();
jQuery("html,body").animate({
scrollTop: loc.top-150//,
//scrollLeft: loc.left
});
return false;
}
@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 / 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 / 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);
}
}