Skip to content

Instantly share code, notes, and snippets.

View Andy-set-studio's full-sized avatar

Andy Bell Andy-set-studio

View GitHub Profile
@Andy-set-studio
Andy-set-studio / auto-collapse.css
Created April 29, 2020 10:19
Auto collapse with flex and gap
.auto-collapse {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
@Andy-set-studio
Andy-set-studio / bash.txt
Created April 28, 2020 19:35
Eleventy in a tweet
echo 'Hello world' > index.md
npx @11ty/eleventy --serve
@Andy-set-studio
Andy-set-studio / split-array-into-chunks.js
Created March 2, 2020 15:03
Split an array into sized chunks
/**
* Takes an array and splits it into sized chunks
* that are <= the passed chunkSize param
*
* @param {Array} source Source array
* @param {Number} chunkSize The max size of each chunk
* @returns {Array} A 2d array of chunks
*/
const splitArrayIntoChunks = (source, chunkSize) => {
if (!source.length) {
@Andy-set-studio
Andy-set-studio / Heading.js
Created February 17, 2020 09:54
Heading React Component
import React from 'react'
import PropTypes from 'prop-types'
const Heading = ({children, cssClass, level}) => {
const Tag = `h${level}`
return <Tag className={cssClass}>{children}</Tag>
}
Heading.propTypes = {
@Andy-set-studio
Andy-set-studio / tweet.txt
Created January 31, 2020 11:23
Tweet text
The <tabs-group> element
You might be thinking “what the heck is that”? This is a custom element that we’ve yet to declare. This is what will be our web component that magically creates our tabs from existing HTML.
This capability is what I absolutely love about custom elements, because it just works, even though I haven’t defined it yet, thanks to the forgiving, declarative nature of HTML. What a fantastic language, right?
For now and until this is defined, it essentially operates as a <div>. Lovely stuff.
@Andy-set-studio
Andy-set-studio / style.css
Created January 27, 2020 17:07
Select SVG images
img[src*='.svg'] {
min-width: 100%;
}
@Andy-set-studio
Andy-set-studio / hosts
Created January 3, 2020 10:53
Block twitter in your /etc/hosts file
# Block Twitter
127.0.0.1 www.twitter.com
127.0.0.1 twitter.com
127.0.0.1 mobile.twitter.com
@Andy-set-studio
Andy-set-studio / is-browser.js
Created December 18, 2019 16:04
Detect wether this is a browser context or not
// Returns true if we’re in a browser
const isBrowser = () => {
return typeof window !== 'undefined';
};
@Andy-set-studio
Andy-set-studio / sleep-fetch.js
Created December 4, 2019 15:18
Sleep fetch function
/**
* Returns a fetch request after a defined timeout
*
* @param {String} url The url that you’re fetching
* @param {Object} options={} Fetch API parameters
* @param {Number} timeout=window.sleepFetchTimeout||1000 You can completely override the timeout globally with window.sleepFetchTimeout
* @returns {Promise}
*/
const sleepFetch = (url, options = {}, timeout = window.sleepFetchTimeout || 0) => {
return new Promise(resolve => {
@Andy-set-studio
Andy-set-studio / local-storage-textarea.js
Created December 2, 2019 15:24
Super basic local storage
const textArea = document.querySelector('textarea');
const storageKey = 'text';
const init = () => {
textArea.value = localStorage.getItem(storageKey);
textArea.addEventListener('input', () => {
localStorage.setItem(storageKey, textArea.value);
});