Skip to content

Instantly share code, notes, and snippets.

View brandonmp's full-sized avatar

brandon brandonmp

View GitHub Profile
@brandonmp
brandonmp / gist:c8597bf7b48d308d57c19aaa32bfa8f6
Created November 18, 2018 02:27
retrieve schema from Segment dashboard
/*
When logged into Segment dashboard and looking at event schema for source, open dev tools and go to Apollo Dev Tools (chrome extension).
In GraphiQL run this query:
query getSourceData($workspaceSlug: String!, $sourceSlug: String!) {
me {
isAdmin
id
__typename
}
@brandonmp
brandonmp / antd-react-animation-styles.css
Created April 11, 2018 22:59
animation css extracted from antd react
/* Even though we import all styles/js modularly, these
* global animation-related styles don't make it, so we add them separately. */
.move-up-appear,
.move-up-enter,
.move-up-leave {
-webkit-animation-duration: .2s;
animation-duration: .2s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-play-state: paused;
@brandonmp
brandonmp / mimic-hover.js
Created July 20, 2017 02:28
mimic-dom-hover-event
const mimicHover = (ele/*: DOMNode*/) => {
var e = document.createEvent('MouseEvents');
e.initEvent('mouseover', true, false);
ele.dispatchEvent && ele.dispatchEvent(e);
}
@brandonmp
brandonmp / paste-to-chrome-console
Last active July 13, 2017 16:50
copy facebook messenger history to clipboard in chrome console
// this works in the chrome console at the messenger.com interface, eg
// https://www.messenger.com/t/yourfriendsname
/* first scroll to top, then copy all msgs, timestamps and names.
* it doesn't scroll "to the top" strictly speaking, but instead just
* scrolls a few times (that's all we needed for our use case).
* you can adjust the # of times it scrolls by extending
* SCROLL_COUNT in scrollToTop().
* results are in TSV format with no header row, eg,
@brandonmp
brandonmp / svg
Created May 14, 2017 03:10
react svg animation
const Icon = props => (
<svg
height={props.height + 'px'}
width={props.width + 'px'}
style={props.style}
viewBox="0 0 89.62 92.78"
>
<g id="Layer_1-2" data-name="Layer 1">
<path
style={{
@brandonmp
brandonmp / unroll.js
Last active March 29, 2021 22:50
unroll me, bro
/* When run in the Chrome console, this function clicks all of the 'unsubscribe' buttons
* on the 'Edit Subscriptions' screen of https://unroll.me/a/subscriptions/new */
const unsubs = [...document.querySelectorAll('.btn.btn--link')].filter(
// collect all the buttons on the page
b => b.textContent === 'Unsubscribe'
); // filter down to just the Unsubscribe buttons
// this function will pause after each click for 750ms to respect their servers
const sleep = () => new Promise(resolve => setTimeout(resolve, 750));
@brandonmp
brandonmp / Tour.jsx
Created February 24, 2017 01:46
react-joyride arrow placement bug
// @flow
import React from 'react'
import Joyride from 'react-joyride'
import tourSteps from './steps'
import 'styles/joyride.css'
type State = {
tourType: 'single' | 'continuous',
showOverlay: boolean,
tourRun: boolean,
@brandonmp
brandonmp / get-big-JSON-nested-item.js
Last active May 29, 2021 18:58
when you have a json too big for memory, here's away to stream out specific keys you want
/* this is a sort of filter function that returns every value that matches a provided path
if you know the path of the node you want, use the function in the other file--it'll be faster */
var JSONStream = require('JSONStream')
var fs = require('fs')
// use immutable for easier assigning of deeply nested props
var Immutable = require('immutable')
var writeJSON = require('simple-json-writing-util.js')
var M = Immutable.Map({})
@brandonmp
brandonmp / async-await sequential loop
Created November 18, 2016 20:37
basically a sequential asynchronous 'foreach' replacement that uses async/await
async function main() {
for (let item of iterable) {
try {
const res = await fetch('http://www.example.com', { method: 'HEAD' })
} catch (e) {
console.error(e)
}
}
}
import Koa from 'koa'
import convert from 'koa-convert'
import webpack from 'webpack'
import webpackConfig from '../build/webpack.config'
import historyApiFallback from 'koa-connect-history-api-fallback'
import serve from 'koa-static'
import proxy from 'koa-proxy'
import _debug from 'debug'
import config from '../config'
import webpackDevMiddleware from './middleware/webpack-dev'