Skip to content

Instantly share code, notes, and snippets.

@jwarby
jwarby / extract-netlify-env-vars.js
Last active November 25, 2021 05:09
Extract Netlify env vars
/* Prints env vars from Netlify deploy settings UI to
* the JavaScript console.
*
* Usage: go to the build & deploy settings section of
* a Netlify site, then run this script.
*/
const envVars = $("#section-environment").querySelectorAll("dl");
const output = [].reduce.call(envVars, (str, dl) => {
const name = dl.querySelector("dt").innerText;
@jwarby
jwarby / input.scss
Created March 22, 2021 10:00
Generated by SassMeister.com.
$color: #ffc107;
@debug lightness($color);
html {
background: lighten($color, 39.2%);
}
@jwarby
jwarby / bootstrap-breakpoint-logger.js
Created November 15, 2019 09:42
Log out Bootstrap (v4) breakpoint changes (add as a snippet in Google Chrome/Chromium and then run)
function getResponseBreakpoint() {
const breakpoints = ['xl', 'lg', 'md', 'sm'];
return breakpoints.find((breakpoint) => {
const div = document.createElement("div");
div.classList.add("d-none", `d-${breakpoint}-block`);
document.body.appendChild(div);
@jwarby
jwarby / autobind-to-arrow.js
Last active November 25, 2020 11:29
JSCodeshift codemod for replacing `autobind` decorators with fat arrow functions
/**
* Replaces instances of @autobind decorators with a fat arrow function.
*
* !! **YMMV - only tested with ES6 class property member functions.**
*
* Given the following input:
*
* class MyClass {
* @autobind
* myAutoboundFunction() {
@jwarby
jwarby / ter-u14n.bdf
Last active March 1, 2017 04:51
Terminus bitmap font patched for Powerline with modified (aligned center-vertical) tilde symbol
STARTFONT 2.1
COMMENT ter-u14n
FONT -xos4-Terminus-Medium-R-Normal--14-140-72-72-C-80-ISO10646-1
SIZE 14 72 72
FONTBOUNDINGBOX 8 14 0 -2
STARTPROPERTIES 21
FAMILY_NAME "Terminus"
FOUNDRY "xos4"
SETWIDTH_NAME "Normal"
ADD_STYLE_NAME ""
@jwarby
jwarby / .eslintrc
Created January 18, 2017 01:23
ESLint configuration file for React/React Native projects
{
"extends": "eslint:recommended",
"parser": "babel-eslint",
"env": {
"node": true,
"mocha": true,
"es6": true
},
"rules": {
"import/default": 2,
@jwarby
jwarby / fsaCompliance.js
Created October 6, 2016 00:26
A saga for redux-saga which verifies that all actions dispatched to the store follow the Flux Standard Action (https://github.com/acdlite/flux-standard-action) pattern. A warning is shown (only once) for each action which violates the pattern.
import { takeEvery } from 'redux-saga'
import { isFSA } from 'flux-standard-action'
const alreadyWarnedAbout = []
export function* fsaCompliance() {
yield* takeEvery('*', function* checkCompliance(action) {
const { type } = action
if (!isFSA(action) && alreadyWarnedAbout.indexOf(type) === -1) {
@jwarby
jwarby / fsaCompliance.js
Last active October 6, 2016 00:27
A middleware for Redux which verifies that all actions dispatched to the store follow the Flux Standard Action (https://github.com/acdlite/flux-standard-action) pattern. A warning is shown (only once) for each action which violates the pattern.
import { isFSA } from 'flux-standard-action'
function createFSAComplianceMiddleware() {
const alreadyWarnedAbout = []
return ({ dispatch, getState }) => next => action => {
const { type } = action
if (!isFSA(action) && alreadyWarnedAbout.indexOf(type) === -1) {
// eslint-disable-next-line no-console
@jwarby
jwarby / tag.vim
Created September 17, 2015 06:35
Append hashtags to the end of a commit message in Vim - intended for adding the initials of peer reviewers, but will work for any tags (you may want to change the function name if so). Usage: :PRed JB EC / :PRed JB / :PRed JB EC DS, etc
function! AddPeerReviewerInitials(...)
" Go to the top of the file
execute ':normal gg'
" Find the first comment line, and go up one line
let lineIndex = search('^#') - 1
" If line is blank, go up another one (my setup adds a new line when amending commit messages)
if !getline(lineIndex)
let lineIndex = lineIndex - 1
@jwarby
jwarby / jshintrc
Last active August 29, 2015 14:10
Personal .jshintrc style guide file
{
/* jwarby's JavaScript Style Guide
* v1.1.0
*
* https://gist.github.com/75aeeab0793a60d14303
* =====================================================
*/
/*
* ENVIRONMENTS