Skip to content

Instantly share code, notes, and snippets.

View brendanmoore's full-sized avatar

Brendan Moore brendanmoore

View GitHub Profile
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
trap cleanup SIGINT SIGTERM ERR EXIT
usage() {
cat <<EOF
function useCachedAbortiveQuery<T>(
query: DocumentNode,
variables: Record<string, unknown>,
deps: Array<any>
) {
const apolloClient = useApolloClient();
const [data, setData] = useState<T>();
const [error, setError] = useState<Error | null>(null);
const [loading, setLoading] = useState<boolean>(true);
if (!Array.prototype.flat) {
Object.defineProperty(Array.prototype, 'flat', {
configurable: true,
value: function flat () {
var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0]);
return depth ? Array.prototype.reduce.call(this, function (acc, cur) {
if (Array.isArray(cur)) {
acc.push.apply(acc, flat.call(cur, depth - 1));
} else {
@brendanmoore
brendanmoore / font-face-rules.js
Last active March 20, 2019 10:50
Log @font-face rules for page
for (var i=0;i<document.styleSheets.length;i++) {
console.group(document.styleSheets[i].href);
for (var j=0;j<document.styleSheets[i].cssRules.length;j++)
{
var rule =document.styleSheets[i].cssRules[j];
if (rule instanceof CSSFontFaceRule) {
console.log(rule.cssText);
}
}
console.groupEnd();
@brendanmoore
brendanmoore / codeshift-react15-to-react16-events.js
Last active February 5, 2018 16:43
Convert JSX on{EventName} from Logical Expression to Ternary shorthand
/**
* Converts:
* From: <button onClick={someIdentifier && this.handleClick} />
* To: <button onClick={someIdentifier ? this.handleClick : undefined} />
*/
export default function transformer(file, api) {
const j = api.jscodeshift;
const interactiveEventTypeNames = [
'blur',
@brendanmoore
brendanmoore / AsyncComponent.test.js
Created January 25, 2018 13:46
Async React, Jest + Enzyme tests example
/**
* @jest-environment jsdom
*/
import React, { Component } from "react";
import { mount } from "enzyme";
const Updated = () => <div>Updated!</div>;
class TimeoutComponent extends Component {
state = {
/**
* Please note this code is just a proof of concept and should not
* be used in production!
*
* Based on https://github.com/airbnb/babel-plugin-dynamic-import-node
*/
import syntax from 'babel-plugin-syntax-dynamic-import';
export default function ({ template, types: t }) {
@brendanmoore
brendanmoore / Secure Sessions Howto
Created August 16, 2016 22:00 — forked from nikmartin/A: Secure Sessions Howto
Secure sessions with Node.js, Connect, and Nginx as an SSL Proxy
Secure sessions are easy, but it's not very well documented, so I'm changing that.
Here's a recipe for secure sessions in Node.js when NginX is used as an SSL proxy:
The desired configuration for using NginX as an SSL proxy is to offload SSL processing
and to put a hardened web server in front of your Node.js application, like:
[NODE.JS APP] <- HTTP -> [NginX] <- HTTPS -> [CLIENT]
To do this, here's what you need to do:
@brendanmoore
brendanmoore / use-case.md
Created September 11, 2015 12:29
Spotify Android use case

Use case for deep linking Spotify Now-playing

I listen to Spotify alot when I am driving, I have a bluetooth handsfree kit with plays the music through my car stereo. I want to reduce the time it takes to get music playing. Currently my flow is:

  • Get in car
  • Get out phone
  • Swipe to unlock
  • Find spotify app
  • Open app
  • Click play
@brendanmoore
brendanmoore / osx_installation.sh
Last active October 15, 2015 08:33
osx_installation
#!/bin/bash
# Command line tools
# Install and accept xcode-select first!!!
# xcode-select --install
# Install Homebrew Dawg!
echo Installing brew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo Installing essentials