Skip to content

Instantly share code, notes, and snippets.

Chris Abrams chrisabrams

Block or report user

Report or block chrisabrams

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View outside-click.tsx
import React from 'react'
import { addEventListener } from 'consolidated-events'
interface Props {
onOutsideClick: any
}
export default class OutsideClickHandler extends React.Component<Props> {
childNode: any
removeMouseDown: any
View gist:a3db362b82996e0be1b9cc881dcaf1f5
class Middleware extends Component {
constructor(props) {
super(props)
this._process()
}
_process() {
const req = // something from browser and props to provide a convention for request information
View ProtectedRoute.js
import React, {Component} from 'react'
import {Route, Redirect} from 'react-router-dom'
import userProvider from 'store/providers/user'
export default class ProtectedRoute extends Component {
constructor(props) {
super(props)
this.inProgress = false
@chrisabrams
chrisabrams / connect.js
Created May 1, 2018
Idea around cleaning up the boilerplate code for connect decorator between React.Component -> Redux.Reducer
View connect.js
import {connect} from 'react-redux'
export default function onConnect(keys) {
const mapStateToProps = (state) => {
const o = {}
for(let i = 0, l = keys.length; i < l; i++) {
const key = keys[i]
@chrisabrams
chrisabrams / get-text.js
Last active Apr 19, 2018
[This does not work for some reason] Use puppeteer to get nodes containing text
View get-text.js
function matchNodes(text) {
try {
const filter = {
acceptNode: function(node){
if(node.nodeValue.toLowerCase().includes(text)){
return NodeFilter.FILTER_ACCEPT
}
@chrisabrams
chrisabrams / index.js
Created Mar 26, 2018
Basic buffer stuff for Node.js
View index.js
function convertTo(type, data) {
switch(type) {
case 'hex':
case 'string':
return Buffer.from(data).toString('hex')
case 'buffer':
case 'Uint8Array':
return Buffer.from(data, 'hex')
}
View example works
// start.js
import React from 'react'
import ReactDOM from 'react-dom'
import { hot } from 'react-hot-loader'
const App = () => <div>Hello World!! 4</div>
const HotApp = hot(module)(App)
ReactDOM.render(<HotApp />, document.getElementById('root'))
View example
// start.js
import React from 'react'
import ReactDOM from 'react-dom'
import { hot } from 'react-hot-loader'
export default function start() {
const App = () => <div>Hello World!! 4</div>
const HotApp = hot(module)(App)
@chrisabrams
chrisabrams / bundleAnalysis.js
Created Sep 23, 2017 — forked from kanavarora/bundleAnalysis.js
Simple utility to track your bundle/chunk sizes with each release
View bundleAnalysis.js
/*
Utility to analyze bundle chunks over versions.
Assumes: webpack has already created the bundle summary json file -> stats.json
Parameters:
version: (Optional) a string that labels the current bundle with the version
provided and saves the summary in a csv file.
Output:
If run the first time, generates a csv file bundleAnalaysis.csv, which
@chrisabrams
chrisabrams / install.js
Created Mar 3, 2017
Bash script to update project dependencies quickly
View install.js
#!/usr/bin/env node
/*
Usage:
Install all production depenencies to their current version: ~/npm/install --prod
Install all production depenencies to their latest: ~/npm/install --prod --latest
Install all production depenencies to their latest and update package.json: ~/npm/install --prod --latest --save
Install all development depenencies to their current version: ~/npm/install --dev
You can’t perform that action at this time.