Skip to content

Instantly share code, notes, and snippets.

View beaucharman's full-sized avatar
💭
🦄 Hackin'

Beau beaucharman

💭
🦄 Hackin'
View GitHub Profile
@beaucharman
beaucharman / compose.js
Last active January 19, 2017 04:33
Returns a function that composes a series of methods together, passing the return value of each from left to right (First method can take multiple arguments)
const compose = (...functions) => (...start) => (
functions.reduce((result, f) => (
(typeof result === 'object') ? f(...result) : f(result)
), start)
)
/**
* Usage
@beaucharman
beaucharman / revive.js
Last active June 22, 2016 23:31
Revive.js; A simple implementation of the awesome http://redux.js.org/
const Revived = () => {
createStore = (reducer) => {
let state
let listeners = []
const getState = () => state
const dispatch = (action) => {
state = reducer(state, action)
@beaucharman
beaucharman / mixin.js
Last active May 25, 2016 06:37
Experimenting with React Higher Order Components as Mixins
// https://gist.github.com/sebmarkbage/ef0bf1f338a7182b6775#gistcomment-1770639
// "If your higher order component need state or lifecycle methods use this:""
const hoc = C => class _hoc extends React.Component {
render() {
return <C {...this.props}/>;
}
}
// "If you don´t need state or lifecycle methods on your HOC this snip is more functional:""
const hoc = C => _hoc(props) => {
return <C { ...props }/>;
@beaucharman
beaucharman / recursiveFlatten.js
Last active May 23, 2016 23:27
Recursively flatten a JS array
function recursiveFlatten(array, ignoreObjects = false) {
let current = []
const arrayLength = array.length
function isType(obj, type = 'Object') {
return Object.prototype.toString.call(obj).indexOf(type) !== -1
}
for (let i = 0; i < arrayLength; i++) {
let result
@beaucharman
beaucharman / forEach.js
Last active May 23, 2016 03:56
A forEach for JavaScript objects
function forEach(obj, callback) {
Object.keys(obj).forEach((item) => {
return callback(obj, item)
})
}
// usage
let obj = { a: 1, b: 2, c: 3 }
let array = []
forEach(obj, function(obj, item) {
@beaucharman
beaucharman / exercises.js
Last active May 13, 2016 12:53
Various exercises from eloquentjavascript.net
// Chapter two - exercise one
// c2e1();
function c2e1() {
var hashCount = 1;
var hashes = '#';
for (;hashCount <= 7; hashCount++) {
console.log(hashes);
hashes += '#';
}
}
@beaucharman
beaucharman / simple-capture-form.php
Last active February 4, 2016 00:52
Takes data from a from and creates and email, also adds an attachment.
<?php
/**
* Simple Capture Form
*
* <input type="hidden" name="first_name" value="" />
* <input type="hidden" name="form_submitted" value="true" />
*
* May need to consider using https://github.com/PHPMailer/PHPMailer
* with an SMTP server if mail from this form goes to spam folder
*/
@beaucharman
beaucharman / _rhythm.scss
Last active January 1, 2016 07:41
rhythm() | Sass function | Creates a funky vertical rhythm.
/**
* Rhythm
* ------------------------------------------------------------------------
* rhythm()
* @version 1.0 | April 25th 2013
* @author Beau Charman | @beaucharman | http://www.beaucharman.me
* @link https://gist.github.com/beaucharman/5459188/
* @param {em} $fontsize | em unit value
* @param {float} $lineheight | decimal value
* @return {em} em unit value
@beaucharman
beaucharman / jquery.equalHeightColumns.js
Last active December 31, 2015 09:49
Responsive, Equal Height Columns
/**
*
* Equal Height Columns
*
* Horizontally Even Columns
*
* @param {object}
* @param {boolean} 'responsive'
* @param {integer} 'responsiveDelay'
* @param {string} 'bindTo'
/**
* accessibleDropDownMenu.js
*
* jquery.accessibleDropDownMenu.js
* @version 2.0 | 14th January 2014
* @author Beau Charman | @beaucharman | http://www.beaucharman.github.io
* @link https://gist.github.com/beaucharman/7348970 |
* http://jsfiddle.net/beaucharman/X2ArC/
* @license MIT license
*/