Skip to content

Instantly share code, notes, and snippets.

View sndrs's full-sized avatar
🐛

Alex Sanders sndrs

🐛
View GitHub Profile
@sndrs
sndrs / css_support.js
Created January 10, 2017 15:19
Generate scoping classes CSS properties and value support
function shimCssSupports() {
var cssToDOMregEx = /([a-z])-([a-z])/g;
function cssToDOMreplacer (str, m1, m2) {
return m1 + m2.toUpperCase();
}
function cssToDOM(name) {
return name.replace(cssToDOMregEx, cssToDOMreplacer).replace(/^-/, '');
}
@sndrs
sndrs / get.js
Last active May 3, 2017 13:43
tiny version of lodash.get https://lodash.com/docs#get
const get = (obj = {}, path = '', defaultValue) =>
path
.replace(/\[(.+?)\]/g, '.$1')
.split('.')
.reduce((o, key) => o[key], obj) || defaultValue;
// PERFORMANCE
// It's slower than lodash (surprise surprise), but it's about 97% smaller:
// https://jsperf.com/get-object-props/4
@sndrs
sndrs / makefile
Created March 7, 2019 14:55
Check for – and use – NVM from a makefile
export PATH := node_modules/.bin:$(PATH)
export SHELL := /usr/bin/env bash
.PHONY: dev
dev: check-nvm install # run `yarn dev` in .nvmrc-mandated node
@bash -l -c 'nvm exec --silent yarn -s dev'
.PHONY: install
install: # install deps using yarn in .nvmrc-mandated node
@bash -l -c 'nvm exec --silent yarn -s'
@sndrs
sndrs / env.sh
Last active March 13, 2020 14:55
Check local environment for Yarn and NVM, and prompt to install if they're missing
#!/bin/bash
log_error () {
echo -e "\x1b[31m$1\x1b[0m"
}
log_info () {
echo -e "\x1b[2m$1\x1b[0m"
}