Skip to content

Instantly share code, notes, and snippets.

View Jimmydalecleveland's full-sized avatar

Jimmy Cleveland Jimmydalecleveland

View GitHub Profile
@Jimmydalecleveland
Jimmydalecleveland / settings.json
Last active February 27, 2019 04:03
vscode workspace settings
{
"gitlens.advanced.messages": {
"suppressShowKeyBindingsNotice": true
},
"workbench.iconTheme": "eq-material-theme-icons",
"workbench.colorTheme": "City Lights",
"materialTheme.fixIconsRunning": false,
"editor.fontSize": 18,
"editor.tabSize": 2,
"editor.fontLigatures": true,
@Jimmydalecleveland
Jimmydalecleveland / universal-handler.js
Last active October 28, 2019 20:18
Universal handleChange function for inputs
handleChange = event => {
const { name, type, value } = event.target;
const val = type === "number" ? parseFloat(value) : value;
this.setState({ [name]: value });
}
@Jimmydalecleveland
Jimmydalecleveland / .eslintrc.json
Created April 21, 2019 18:59
Personal eslint starter
{
"extends": ["airbnb", "plugin:prettier/recommended", "prettier/react"],
"env": {
"jest": true
},
"rules": {
"no-plusplus": "off",
"jsx-a11y/anchor-is-valid": [
"error",
{
@Jimmydalecleveland
Jimmydalecleveland / bigOExamples--Occurrences.js
Last active June 8, 2019 15:40
Given 2 arrays, compare occurrences from the first array, squared, to the second array
// O(n^2)
// function same(arr1, arr2) {
// if (arr1.length !== arr2.length) return false
// let result = true;
// arr1.forEach((num) => {
// const currentIndex = arr2.indexOf(num * num)
// if (currentIndex === -1) {
// result = false
@Jimmydalecleveland
Jimmydalecleveland / bigOExamples--sumZero.js
Last active June 12, 2019 15:04
Given an array of sorted numbers, find the first 2 values that equal zero
/* Inefficient example would be a nested loop -- O(n^2)
** Below version uses multiple pointers to achieve O(n)
*/
function sumZero(arr) {
let left = 0;
let right = arr.length - 1;
while(left < right) {
let sum = arr[left] + arr[right]
@Jimmydalecleveland
Jimmydalecleveland / countUniqueValues.js
Created June 23, 2019 19:48
Given an array of sorted values, return the number of unique values with O(n) complexity
/*
** Given an array of sorted values, return the number of unique values
**
** Method: Use 2 pointers (lastUniqueIndex and i) to mutate sorted array and
** return lastUniqueIndex + 1 for result
*/
function countUniqueValues(arr) {
if (!arr.length) return 0
let lastUniqueIndex = 0;
@Jimmydalecleveland
Jimmydalecleveland / method-chaining-composition.js
Last active June 26, 2019 18:06
Example of a way to compose a chain of methods conditionally for libraries that use method chaining
const compose = funcObjects => startingInstance =>
funcObjects.reduce(
(composed, currentFunc) =>
composed[currentFunc.method](currentFunc.argument),
startingInstance
);
// Example of how compose would be called with static data
// const emailComposed = compose(
// { method: "email", argument: "Enter an email, tallywacker." },
@Jimmydalecleveland
Jimmydalecleveland / button.js
Last active August 1, 2019 15:06
Contentful Migration of button to CTA.
// 1) Runs first, Initial creation of 'button'
const button = migration
.createContentType('button')
.name('Button')
.description(
'Global button type including things such as site links and call now buttons'
)
.displayField('identifier')
button
.createField('identifier')
@Jimmydalecleveland
Jimmydalecleveland / blog-styled-button-example.js
Created August 22, 2019 00:02
An intro example of styled components from their docs
// Intro example from Styled Components docs
const Button = styled.button`
background: ${props => props.primary ? "palevioletred" : "white"};
color: ${props => props.primary ? "white" : "palevioletred"};
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border: 2px solid palevioletred;
border-radius: 3px;
function taggedTemplate(stringArray, variable) {
console.log(stringArray)
// [ 'The string will be split here: ', ' Then it resumes here.' ]
console.log(variable)
// I am the great divider!
return `${stringArray[0]}${variable}${stringArray[1]}`
}