Skip to content

Instantly share code, notes, and snippets.

@grrowl
grrowl / flattenjson.html
Last active January 2, 2016 08:29
Flattens multi-level JSON objects (useful for converting complex JSON to CSV format)
<style>
textarea { height: 400px; width: 100%; }
</style>
<h1>flatten json</h1>
<textarea id="data">[]</textarea>
<button id="goByLine">line-by-line</button>
<button id="goWhole">as whole object</button>
<textarea id="result"></textarea>
@grrowl
grrowl / consolefix.js
Last active August 29, 2015 13:56
<IE8 JS Console fixer
if (typeof window.console === "undefined") {
var methods = ['log', 'info', 'error', 'debug', 'warn', 'assert', 'clear', 'dir', 'trace', 'time', 'timeEnd'];
console = {};
for (var key in methods)
console[methods[key]] = function () {};
}
@grrowl
grrowl / awesomecss.md
Last active August 29, 2015 14:05
Awesome CSS (and other front-end goodies)

Awesome CSS

A starting point for awesome CSS (and Sass, and Less) resources, inspired by Awesome Awesomeness everywhere. Still fleshing this out as I go, feel free to fork/contribute.

Structure

Tools

@grrowl
grrowl / host-matching-proposal.md
Last active August 29, 2015 14:16
Subdomain/host matching in react-router

We have a rapidly growing React application which renders on both the server- and client-sides. Some sections of the app are on separate subdomains. The same app uses the same assets across many subdomains, so we control it all through the one runtime. This mean react-router needs to be able to distinguish which host or subdomain it's on.

Proposal

  • HostRoute which subclasses Route and is aware of the host via a static method HostRoute.setHost(url.parse(res.url).hostname)
  • Static method called before Router.run() (on init of app) i.e. HostRoute.setHost(url.parse(req.url).hostname) and/or HostRoute.setHost(window.location.hostname)
  • Makes sense, since host will never change during the lifetime of the application, a significantly lighter approach and "opt-in" for those who require it.
  • Will require addition to modules/Match to ask the Route itself if it might be a match (if host matc
@grrowl
grrowl / fetchDataComponent.jsx
Last active October 19, 2015 20:33
redux and react-router helper to provide (dispatch, storeState) to a static fetchData method
'use strict';
/*
# FetchData
If property callback `if(storeState)` return true, calls property callback
`fetchData(dispatch, storeState)` so it may dispatch FETCH actions.
## Usage:
@grrowl
grrowl / forward80.sh
Created September 23, 2015 00:30
Forwards port 80 to another port (*nix, OSX up to 10.11)
#!/usr/bin/env sh
sudo ssh -L 0.0.0.0:80:127.0.0.1:9000 -N tom@localhost
@grrowl
grrowl / Twitter.gs
Created April 27, 2016 08:26
Google Docs script to automate Twitter posting
// source: https://ctrlq.org/code/19702-twitter-image-upload
function autoTweet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("schedule"); // This must match the sheet name!
var rows = sheet.getRange("A:D").getValues();
var titleList = [], newValues = [],
response, doc, title;
var twitterCallback = function(rowIndex, err, result) {
@grrowl
grrowl / githubDelayedMerge.user.js
Created May 10, 2016 07:46
GitHub: click anywhere on the "merge message" (with disabled button) and it'll wait until the button enables and click it for you.
(function () {
function handleLoaded() {
var butan = document.querySelector('.merge-message .btn[disabled]')
var checkTimer;
if (butan) {
butan.parentElement.addEventListener('click', function handleClick(event) {
if (checkTimer) {
@grrowl
grrowl / code-review.sh
Created June 2, 2016 00:10
code-review.sh <branch to review> [<base branch>]
#!/bin/bash
DEFAULT_BASE="develop"
if [ -z "$*" ]; then echo "Usage: code-review.sh [review branch] [case compare branch]"; exit 0; fi
REVIEW_BRANCH=$1
BASE_BRANCH=${2-$DEFAULT_BASE}
echo "Checking out $REVIEW_BRANCH"
@grrowl
grrowl / Signature.js
Created November 19, 2016 02:35
React component to provide ed25519 key generation, signing and verification
import React, { Component, PropTypes } from 'react'
import elliptic, { eddsa as EdDSA } from 'elliptic'
function toHex(arr) {
return elliptic.utils.toHex(arr).toUpperCase()
}
function fromHex(hex) {
return elliptic.utils.toArray(hex, 'hex')