Skip to content

Instantly share code, notes, and snippets.

View brandonmp's full-sized avatar

brandon brandonmp

View GitHub Profile
@brandonmp
brandonmp / 0_reuse_code.js
Created November 13, 2015 08:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@brandonmp
brandonmp / resize-imgs
Created November 27, 2015 00:32
shell script to resize every image in a directory
find /path/to/img/dir -type f -exec sh -c '
sudo convert -resize 150% "$0" "$0"
' {} \;
@brandonmp
brandonmp / configure_logging.py
Created December 1, 2015 00:22
configure logging in ipython notebook
import logging
#SET LOG NAME:
logname = "article_cleaner.log"
logger = logging.getLogger()
fhandler = logging.FileHandler(filename=logname, mode='a')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fhandler.setFormatter(formatter)
logger.addHandler(fhandler)
logger.setLevel(logging.DEBUG)
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'
@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)
}
}
}
@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 / 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 / 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 / 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 / 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,