Skip to content

Instantly share code, notes, and snippets.

View markmur's full-sized avatar
📱

Mark Murray markmur

📱
View GitHub Profile
@markmur
markmur / pre-push
Created March 14, 2016 16:17
Git Pre Push
#!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref --short HEAD)
if [ $protected_branch = $current_branch ]
then
read -p "You should create a PR rather than push to master. Are you absolutely sure you want to proceed? [y/n]" -n 1 -r < /dev/tty
echo
if echo $REPLY | grep -E '^[Yy]$' > /dev/null
/@include ([\w\-]+)\((.+)\)/ig
replace: $1: $2
@markmur
markmur / comp.sh
Last active April 28, 2016 14:44
Create New React Component
#!/bin/bash
printf "\e[92mWhat would you like to call your component?\e[0m $1"
read NAME
NAME=${NAME:-$1}
if [ -z "$NAME" ]; then
printf "You must provide a component name! \n";
exit 1;
fi
@markmur
markmur / index.html
Created April 11, 2016 23:07
Webpack Hot Reload
<script src="/static/bundle.js"></script>
@markmur
markmur / webpack.config.js
Created April 19, 2016 13:05
Webpack Hot Reload
'use strict';
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: [
'babel-polyfill',
'webpack-dev-server/client?http://localhost:8080',
@markmur
markmur / _mixins.scss
Last active April 19, 2016 14:37
Programatically generate a css button
@function extend($obj, $ext-obj) {
@return map-merge($obj, $ext-obj);
}
/**
* Usage
* @method button
* @param {Object} $opts - options
* @usage
*
@markmur
markmur / PromiseMiddleware.js
Created October 5, 2016 18:35
Redux Promise Middleware
/**
* Promise Middleware is used to avoid having to dispatch 3 events for every
* request (request, success and error)
*
* You can dispatch 1 event with a `promise` property and in turn the Middleware
* will automatically dispatch the 3 events.
* @method promiseMiddleware
* @return {Promise} returns the promise
*/
export default function promiseMiddleware({ getState }) {
@markmur
markmur / currying.js
Created November 17, 2016 22:29
Recursive Curry Add
function add(x) {
var fn = (n) => add(n + x);
fn.toString = () => x;
return fn;
}
@markmur
markmur / imagePreloader.js
Created April 26, 2017 10:21
Preload images
const preloadImages = (images, callback) => {
const loaded = [];
const failed = [];
const imageRequests = images.map(image => {
const img = new Image();
img.src = image;
return new Promise((resolve) => {
img.onload = () => {
@markmur
markmur / preloadImages.js
Created June 6, 2017 18:38
Preload Images with Promises
const preloadImages = (images) => Promise.all(images.map(image =>
new Promise(resolve => {
const img = new Image();
img.onload = () => (resolve(image));
img.onerror = () => (resolve(image));
img.src = image;
})
));