Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Simmonds simmo

View GitHub Profile
View machine.js
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@simmo
simmo / renderHookServer.ts
Last active May 13, 2019
React SSR hook testing
View renderHookServer.ts
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() {
View SketchSystems.spec
intro*
NEXT -> config
config
PREV -> intro
package*
NEXT -> colour
colour
PREV -> package
NEXT -> wheels
wheels
@simmo
simmo / absolute.scss
Created Sep 6, 2017
Ideas for absolute Sass helper
View absolute.scss
@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 / promise.js
Created Dec 21, 2016
Redux Middleware: Cacheable Promises
View promise.js
// 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 / helpers.js
Created Dec 16, 2016
Redux helpers
View helpers.js
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 / flightplan.js
Created Nov 19, 2015
Capistano-like Node deployment using Flightplan
View flightplan.js
'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 / widowKiller.js
Created Aug 7, 2015
JavaScript function to remove widows form elements.
View widowKiller.js
// 'elements' should be a string of the CSS selectors you wish to match
function widowKiller(elements) {
var nodes = document.querySelectorAll(elements);
function removeWidow(element) {
var walk = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null, false);
var node, arr;
while(node = walk.nextNode()) {
arr = node.nodeValue.split(' ');
@simmo
simmo / throttle.js
Last active Jun 22, 2018
JavaScript Throttle using requestAnimationFrame
View throttle.js
function throttle(type, name, obj) {
var running = false;
obj = obj || window;
var func = function() {
if (running) return;
running = true;
@simmo
simmo / _bem.scss
Last active Jul 24, 2017
Sass: BEM Mixins
View _bem.scss
$bem-element-separator: '__' !default;
$bem-modifier-separator: '--' !default;
// BEM: Block (New)
@mixin new($name, $description) {
/**
* #{$name}
* #{$description}
*/
.#{$name} {