Skip to content

Instantly share code, notes, and snippets.

// Set base multiplier for use with rem units
html { font-size: 4px }
// Set body back to default size
body { font-size: 4rem }
// Add spacing to elements without worrying if vertical rythm matches the scale
h1 { margin: 0 0 10rem 0 }
@wking-io
wking-io / Monads.js
Created December 8, 2017 14:18
Function Programming Categories
const Right = v => ({
chain: f => f(v),
map: f => Right(f(v)),
fold: (f, g) => g(v),
});
const Left = v => ({
chain: f => f(v),
map: f => Left(f(v)),
fold: (f, g) => f(v),
@wking-io
wking-io / remove-class.js
Last active October 11, 2017 19:47
How can I pass arguments to a callback function?
import transformSibs from 'transform-sibs';
// Use a curried function to pass more arguments to callback
const removeClass = className => el => el.classList.remove(className);
// get element from DOM
const $item = document.querySelector('.item');
// Transform all siblings of $item and remove class 'active'
transformSibs($item, removeClass('active'));
@wking-io
wking-io / transform-sibs.js
Created October 11, 2017 19:43
How can I transform siblings of an element?
const transformSibs = (el, callback) => Array
.from(el.parentNode.childNodes)
.filter(child => child.nodeType == 1 && child != el)
.forEach(sibling => {
callback(sibling);
return sibling;
});
@wking-io
wking-io / get-sibs.js
Last active October 10, 2018 12:32
How do I get all the siblings of an element?
const getSibs = (el) => Array
.from(el.parentNode.childNodes)
.filter(child => child.nodeType == 1 && child != el);
@wking-io
wking-io / magical-underline.scss
Last active October 11, 2017 19:38
How do I make a magical underline that works on line breaks and can be any color I want? #library #scss
.underline--magical {
background-image: linear-gradient;
background-repeat: none;
background-size: 100% 4px; // how-thick;
background-position: 0 8px; // how-far-down;
}
@wking-io
wking-io / header.php
Last active October 11, 2017 19:00
Add responsive background images for slider and preload them. #library #wordpress
<?php
// make sure it is the correct template
if (is_page_template( 'templates/template.php' )) :
$slider_posts = array();
// check if the repeater field has rows of data
if( have_rows('slider_posts') ) :
// loop through the rows of data
while ( have_rows('slider_posts') ) : the_row();
// display a sub field value
if (!empty(get_sub_field('the_post'))) :
@wking-io
wking-io / factory.js
Last active October 11, 2017 02:59
Note to self: Remember to assign the destructured array/object an empty array/object when giving destructured function arguments default values.
const makeSandwich = ({
bread = 'wheat',
meat = 'turkey',
cheese = 'american',
toppings = []
} = {}) => ({
bread,
meat,
cheese,
toppings,
@wking-io
wking-io / REST.txt
Created October 5, 2017 14:23
REST Book request
GET /books/:id
@wking-io
wking-io / create.bash
Last active October 5, 2017 14:22
Create New Create React App Project
npx create-react-app my-app
cd my-app/
npm start