Skip to content

Instantly share code, notes, and snippets.

View sndrs's full-sized avatar
🐛

Alex Sanders sndrs

🐛
View GitHub Profile
@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"
}
@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 / non-blocking-document.write.html
Created August 27, 2015 12:00
Override document.write to prevent 3rd parties injecting blocking scripts
<!DOCTYPE html>
<html>
<head>
<title></title>
<script>
(function(Document) {
Document.prototype.write = function(s) {
var allScripts = document.getElementsByTagName('script'),
thisScript = allScripts[allScripts.length-1];
@sndrs
sndrs / auto_nvm_use.sh
Last active March 18, 2024 11:29 — forked from jusopi/check.sh
Automatically set node version per project using .nvmrc file
# This will run `nvm use` everytime you change directory, if
# 1. an .nvmrc file is present
# 2. there is no .nvmrc but you're not using your default node
# Add it to your `.bash_profile` (or wherever else is suitable for your setup).
enter_directory(){
if [ "$PWD" != "$PREV_PWD" ]; then
PREV_PWD="$PWD";
if [ -e ".nvmrc" ]; then
nvm use;