Skip to content

Instantly share code, notes, and snippets.

View simmo's full-sized avatar

Mike Simmonds simmo

View GitHub Profile
@simmo
simmo / flightplan.js
Created November 19, 2015 09:03
Capistano-like Node deployment using Flightplan
'use strict'
var join = require('path').join
var plan = require('flightplan')
const application = 'example.com'
const deployTo = join('/var', 'www', application)
const repoUrl = 'https://github.com/example/example.git'
const branch = 'master'
const keepReleases = 3
@simmo
simmo / helpers.js
Created December 16, 2016 12:26
Redux helpers
export const mapDispatchToProps = actions => dispatch => Object.keys(actions).reduce((obj, key) => {
obj.actions[key] = bindActionCreators(actions[key], dispatch)
return obj
}, { actions: {} })
// connect(null, mapDispatchToProps({ action1, action2 }))(ReactComponent)
// => this.props.actions.action1, this.props.actions.action2
export const mapStateToProps = properties => store => properties.reduce((obj, property) => {
if (store.hasOwnProperty(property)) {
@simmo
simmo / promise.js
Created December 21, 2016 08:35
Redux Middleware: Cacheable Promises
// Utility to check if value is a Promise
function isPromise(value) {
if (value !== null && typeof value === 'object') {
return value && typeof value.then === 'function'
}
return false
}
// Cache
@simmo
simmo / absolute.scss
Created September 6, 2017 16:05
Ideas for absolute Sass helper
@mixin position($position, $args: null) {
$offsets: bottom left right top;
position: $position;
@if (type-of($args) == 'list') {
@each $offset in $offsets { // 3
$index: index($args, $offset); // 4
@if $index { // 5
@simmo
simmo / renderHookServer.ts
Last active May 13, 2019 09:37
React SSR hook testing
import { createElement } from 'react'
import { renderToString } from 'react-dom/server'
export default function renderHookServer(
hookInit: Function
): // eslint-disable-next-line @typescript-eslint/no-explicit-any
any {
let hookOutput = undefined
function HookWrapper() {
@simmo
simmo / machine.js
Created July 14, 2020 22:05
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions