Skip to content

Instantly share code, notes, and snippets.

💭
🦄 Hackin'

Beau beaucharman

💭
🦄 Hackin'
View GitHub Profile
@beaucharman
beaucharman / debounce.js
Last active Jun 17, 2020
An ES6 implementation of the debounce function. "Debouncing enforces that a function not be called again until a certain amount of time has passed without it being called. As in 'execute this function only if 100 milliseconds have passed without it being called.'" - CSS-Tricks (https://css-tricks.com/the-difference-between-throttling-and-debounc…
View debounce.js
function debounce(callback, wait, immediate = false) {
let timeout = null
return function() {
const callNow = immediate && !timeout
const next = () => callback.apply(this, arguments)
clearTimeout(timeout)
timeout = setTimeout(next, wait)
@beaucharman
beaucharman / throttle.js
Last active Jun 14, 2020
An ES6 implementation of the throttle function. "Throttling enforces a maximum number of times a function can be called over time. As in 'execute this function at most once every 100 milliseconds.'" - CSS-Tricks (https://css-tricks.com/the-difference-between-throttling-and-debouncing/)
View throttle.js
function throttle(callback, wait, immediate = false) {
let timeout = null
let initialCall = true
return function() {
const callNow = immediate && initialCall
const next = () => {
callback.apply(this, arguments)
timeout = null
}
View TerminalNotes.md

Terminal Notes and Snippets

Configuration

Show full path in finder

defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES

@beaucharman
beaucharman / reactLifecycleMethods.notes.md
Last active Mar 15, 2019
Notes: A cheat sheet for the React Component Lifecycle Methods
View reactLifecycleMethods.notes.md

Mounting

componentWillMount
componentWillMount()
  • setState() can be called here and won't cause a rerender

@beaucharman
beaucharman / pureSplice.js
Last active Feb 22, 2019
An ES6 / pure function implementation of the JS splice method that returns an object of the new array and the removed elements
View pureSplice.js
function safeSplice(array, start, deleteCount, ...replace) {
const removed = array.splice(start, deleteCount, ...replace)
return {
array: array,
removed: removed,
}
}
/** usage
const array = [1, 2, 3, 4, 5, 6]
@beaucharman
beaucharman / example.js
Last active Feb 4, 2019
A conditional higher order function
View example.js
unless(booleanExpression, () => {
// Then callback
})
View Portal_Teams.addTeamMember.request.js
// Portal_Teams.addTeamMember.request.js
{
...
data: {
ClassName: 'Platform_Teams',
MethodName: 'addTeamMember',
Parameter: {
name: 'Name',
practitionerId: '0050k000000FtmGAAS',
clients: [ // Group and all it's entities
@beaucharman
beaucharman / ACF_Layout.php
Last active Nov 3, 2017
Logical layout automation for Advanced Custom Fields and it's Flexible Content Field add on. http://www.advancedcustomfields.com/ http://www.advancedcustomfields.com/add-ons/flexible-content-field/
View ACF_Layout.php
<?php
/**
* ACF Layout
* @version 1.0 | November 12th 2013
* @author Beau Charman | http://twitter.com/beaucharman
* @link https://gist.github.com/beaucharman/7181406
* @license MIT license
*
* Logical layout automation for Advanced Custom Fields and it's Flexible Content Field add on.
@beaucharman
beaucharman / git-rebase.notes.md
Last active Nov 1, 2017
Notes: Git rebase process
View git-rebase.notes.md
  1. git checkout <master>
  2. git merge origin <master>
  3. git checkout <feature>
  4. git rebase <master>
  5. deal with any conflicts
  6. git add .
  7. git rebase --continue
  8. git push origin <feature> --force
  9. 😎
@beaucharman
beaucharman / deepArrayMerge.js
Last active Aug 15, 2017
deepArrayMerge.js
View deepArrayMerge.js
// const { unionBy, isArray, merge, find } = _
const deepArrayMerge = (initial, replacement, key) => unionBy(initial, replacement, key)
.map(item => merge({}, item, find(isArray(replacement) ? replacement : [replacement], { [key]: item[key] })))
You can’t perform that action at this time.