Skip to content

Instantly share code, notes, and snippets.

View justingreenberg's full-sized avatar

justin justingreenberg

View GitHub Profile
import * as assert from 'assert'
import * as crypto from 'crypto'
import * as data from './data'
function ascendingByProp(prop) {
return (a, b) => b[prop] - a[prop]
}
function descendingByProp(prop) {
@justingreenberg
justingreenberg / headers.ts
Created February 23, 2020 06:05
Recursively prepend a header banner to all files in directory
const fs = require('fs').promises;
const path = require('path');
interface Params {
dir: string;
header: string;
predicate: (filePath: string) => Boolean;
}
interface WalkTree {
import React from 'react'
import ReactDOM from 'react-dom'
import { createStore } from 'redux'
import { connect, Provider } from 'react-redux'
import './styles.css'
// Log unnecessary re-renders
require('@welldone-software/why-did-you-render')(React, {
trackAllPureComponents: true,
include: [/^ConnectFunction/],
@justingreenberg
justingreenberg / styled-media-queries.js
Last active June 17, 2018 16:26
Media queries for styled-components
const sizes = {
giant: 1170,
desktop: 992,
tablet: 768,
phablet: 572,
phone: 376
}
export const media = Object.keys(sizes).reduce((accumulator, label) => {
accumulator[label] = (...args) => css`
import { exec } from 'child_process'
import debug from 'debug'
export default {
check: cwd => new Promise((resolve, reject) => {
let resolveObj = {
behind: false,
amount: 0,
branch: 'origin/stable'
}
import assert from 'assert'
import Immutable from 'immutable'
const batchSetters = state => {
state.set('a', 1)
state.set('b', 2)
state.set('c', 3)
return state
}
@justingreenberg
justingreenberg / proxy-trace.js
Last active January 11, 2017 06:58
Simple tracing using ES Proxies
import assert from 'assert'
const tracer = async obj => {
const trace = {}
let order = []
const object = new Proxy(obj, {
get (target, prop) {
order = order.concat(prop)
trace[prop] = Reflect.has(trace, prop) ? trace[prop] + 1 : 1
import fs from 'fs'
import { interpolateName } from 'loader-utils'
// webpack config
const publicPath = 'static'
const filenameTemplate = '[name].[hash].[ext]'
const extensions = [
'png', 'jpg', 'jpeg', 'gif',
'ico', 'svg', 'otf', 'eot', 'svg',
'ttf', 'woff', 'woff2'
### Keybase proof
I hereby claim:
* I am justingreenberg on github.
* I am jkg (https://keybase.io/jkg) on keybase.
* I have a public key ASDIroaoNEZCCD8O4tjhCSgtC7tzKSP_KD7sTXgZFgpsnwo
To claim this, I am signing this object: