Skip to content

Instantly share code, notes, and snippets.

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

Beau beaucharman

💭
🦄 Hackin'
View GitHub Profile
@beaucharman
beaucharman / throttle.js
Last active November 12, 2022 15:39
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/)
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
}
@beaucharman
beaucharman / ACF_Layout.php
Last active May 10, 2022 21:27
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/
<?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 / debounce.js
Last active February 25, 2022 20:35
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…
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)

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 March 15, 2019 16:09
Notes: A cheat sheet for the React Component Lifecycle Methods

Mounting

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

@beaucharman
beaucharman / pureSplice.js
Last active February 22, 2019 21:34
An ES6 / pure function implementation of the JS splice method that returns an object of the new array and the removed elements
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 February 4, 2019 02:01
A conditional higher order function
unless(booleanExpression, () => {
// Then callback
})
// 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 / git-rebase.notes.md
Last active November 1, 2017 17:52
Notes: Git rebase process
  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 August 15, 2017 07:10
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] })))