Skip to content

Instantly share code, notes, and snippets.

View dstreet's full-sized avatar
👾

David Street dstreet

👾
View GitHub Profile
@dstreet
dstreet / flatten-array.js
Created October 18, 2017 17:54
Flatten a JS array
const assert = require('assert')
const flatten = arr => arr.reduce((acc, el) => {
return acc.concat(Array.isArray(el) ? flatten(el) : el)
}, [])
assert.deepEqual(flatten([1, 2, 3, 4]), [1, 2, 3, 4])
assert.deepEqual(flatten([1, [2, 3], 4]), [1, 2, 3, 4])
assert.deepEqual(flatten([1, [2, [3]], 4]), [1, 2, 3, 4])
@dstreet
dstreet / next-hoc.js
Last active August 27, 2021 08:33
Example HOC with Next.js
import React from 'react'
/*
* Higher order component that passes `getInitialProps` through
* to the child component
*/
const HOC = function(Child) {
return class Higher extends React.Component {
static getInitialProps(ctx) {
return Child.getInitialProps(ctx)

Keybase proof

I hereby claim:

  • I am dstreet on github.
  • I am dstreet (https://keybase.io/dstreet) on keybase.
  • I have a public key ASAvnCiF_zOsJqFs2b6enAScivpRDOIfAHv03DFHBlVGzQo

To claim this, I am signing this object:

@dstreet
dstreet / .vimrc
Created July 23, 2015 13:07
My vim config
syntax on
colorscheme itg_flat "https://github.com/cdmedia/itg_flat_vim
set number
set tabstop=4
let g:netrw_liststyle=3
@dstreet
dstreet / tictactoe.js
Last active July 28, 2022 05:52
Simple Tic Tac Toe Game in Node
var readline = require('readline');
var TicTacToe = function(readline) {
/*
* Private API
* ------------------------------------------------------------------------
*/
var _rl = null
@dstreet
dstreet / jQuery.backgroundCover.js
Last active August 29, 2015 14:00
jQuery.backgroundCover
/*
* jQuery.backgroundCover.js
* --------------------------------------------------------
* A polyfill for the background-size: cover CSS property.
*
* Copyright: David Street 2014
*/
(function($) {