Skip to content

Instantly share code, notes, and snippets.

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

Beau beaucharman

💭
🦄 Hackin'
View GitHub Profile
// 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 / 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] })))
@beaucharman
beaucharman / example.js
Last active February 4, 2019 02:01
A conditional higher order function
unless(booleanExpression, () => {
// Then callback
})
@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 / 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 / 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 / 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 / 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)
@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 / 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