Skip to content

Instantly share code, notes, and snippets.

View export-mike's full-sized avatar
📱
GO, React, React Native, Node.js in Syndey Australia

Mike James export-mike

📱
GO, React, React Native, Node.js in Syndey Australia
View GitHub Profile
@export-mike
export-mike / location.js
Last active March 5, 2016 17:53
Cradle wrapped up into a simple and lean api for creating simple and complex models in couchdb.
import randomString from 'random-string';
import Uuid from 'node-uuid';
import {couchUpdate, couchSave, couchView, couchDesignDoc} from '../helpers/couch';
const TYPE = 'Location';
export const save = (location) => {
return couchSave(Uuid.v4(), {
type: TYPE,
address: location.address,
postcode: location.postcode,
@export-mike
export-mike / song.js
Last active April 3, 2016 19:38
Old Mc donald had a farm, intel edison with grove buzzer and lcd
var LCD = require('jsupm_i2clcd');
var myLcd = new LCD.Jhd1313m1 (0, 0x3E, 0x62);
var messages = [['Old Mc Donald', 'Had A farm', [18,239,99]],
['Eee I Eee I Oh', 'an on that farm he had a ', [18,239,99]],
['DUck', 'There a quack everwhere a quack quack', [18,239,99]]];
var pos = 0;
setInterval(function() {
var message=messages[pos];
@export-mike
export-mike / requestOnLoadExample.js
Created April 15, 2016 10:12
built a higher order component for a redux app its inspired by redux form but its for a specific use case. say you have a route/container that needs to fetch some data on componentWillMount and have the flags provided for submitting and error. this higher order component means you don’t need to write any flux stuff, just use the HOC
import requestOnLoad from 'request-on-load';
const {myApiRequest} from '../ApiClient';
class MyComponent extends React.Component {
componentWillMount() {
this.props.request(() => myApiRequest());
}
return (
@export-mike
export-mike / promote-to.sh
Last active June 9, 2016 09:37
promote-to { qa | uat | default } { patch | minor | major }
#!/usr/bin/env bash
export NOHGHOOK=true
TO="$1"
SEMVER_ACTION="$2"
FROM="$(hg branch)"
echo "promoting $FROM to $TO"
if [[ "$TO" == "qa" ]] || [[ "$TO" == "uat" ]] || [[ "$TO" == "default" ]]; then
if [[ "$SEMVER_ACTION" == "major" ]] || [[ "$SEMVER_ACTION" == "minor" ]] || [[ "$SEMVER_ACTION" == "patch" ]]; then
npm version $SEMVER_ACTION
fi
@export-mike
export-mike / build
Created June 29, 2016 13:59
react-docgen build file for typical react redux apps, you can then call this from you CI build or pre commit or do it manually whatever.
#!/usr/bin/env bash
rm -rf views containers components
mkdir views && cd views
react-docgen ../../src/views/ --resolver findAllComponentDefinitions --ignore test | ../buildDocs && cd ..
mkdir containers && cd containers
react-docgen ../../src/containers/ --resolver findAllComponentDefinitions --ignore test | ../buildDocs && cd ..
mkdir components && cd components
react-docgen ../../src/components/ --resolver findAllComponentDefinitions --ignore test | ../buildDocs && cd ..
@export-mike
export-mike / createReducer.js
Created February 27, 2017 00:48
a helper function to transform a map into a nice clean reducer with no switch statements.
/**
* Utility method to create a reducer from a map,
* with initial state
* @param initialState
* @param reducerMap
* @returns {Function}
*/
export default function createReducer(initialState, reducerMap) {
return (state = initialState, action) => {
@export-mike
export-mike / redux.js
Created March 14, 2017 04:51
How Does Redux Work?
import compose from 'recompose/compose';
import EventEmitter from 'event-emitter';
const combineReducers = reducersMap => {
const arrayOfReducers = Object.keys(reducersMap)
.reduce((acc, r) => [...acc, reducersMap[r]], []);
return compose.apply(null, arrayOfReducers);
}
const dispatch = reducers => action => reducers(action);
@export-mike
export-mike / .bash
Created April 2, 2017 05:06
react-init
yarn add webpack@^2 babel-core babel-loader babel-preset-react babel-preset-stage-2 prettier eslint@^3 react@^15 react-dom@^15enzyme nightmare jest eslint-config-prettier prettier-eslint-cli styled-components --dev && git init && git ignore-io node && echo '{"extends":"prettier"}' > .eslintrc && echo '{"presets": ["stage-2", "react"]}' > .babelrc
@export-mike
export-mike / lighthouse.io.js
Last active April 2, 2017 05:09
lighthouse.io code test
import { compose, pure } from 'recompose'
import { Component } from 'react'
import Radium from 'radium' // great styling library! I
// I'd also consider styled-components now its really neat and much more react style
/** for example purposes we've got some other components that are not defined,
I've added a spinner which would render a CSS animation in place of the table.
I've got a Button comonent which renders the styled buttons we have in the screenshot, they could have clicks attached.
@export-mike
export-mike / dropDataGraphCool.js
Created July 19, 2017 13:07
A utility Script for cleaning out tables in graphcool
require('dotenv').config();
const { GraphQLClient } = require('graphql-request');
const client = new GraphQLClient(process.env.ENDPOINT, { headers: {
'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`
}});
const query = T => `
query Get${T}s {
all${T}s {
id