This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# BUGS: | |
# 1. not adding settings to .zshrc from below (i.e. default theme, packages, custom functions, etc.) | |
# 2. not auto-hiding doc | |
# 3. not auto-hiding menu bar | |
# 4. not adding .vimrc | |
# 5. not automatically copying iTerm profile, Option + Space not setup to toggle iTerm, doesn't default to opening iTerm at startup | |
# | |
# Bootstrap script for setting up a new OSX machine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const css2obj = (strings, ...vals) => { | |
const css = strings.reduce((acc, str, i) => acc + str + (vals[i] || ''), '') | |
const r = /(?<=^|;)\s*([^:]+)\s*:\s*([^;]+)\s*/g, o = {} | |
css.replace(r, (m,p,v) => o[p.replace(/-(.)/g, (_,p) => p.toUpperCase())] = v) | |
return o | |
} | |
const actual = css2obj` | |
position: fixed; | |
left: 50%; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const classToObject = theClass => { | |
const originalClass = theClass || {} | |
const keys = Object.getOwnPropertyNames(Object.getPrototypeOf(originalClass)) | |
return keys.reduce((classAsObj, key) => { | |
classAsObj[key] = originalClass[key] | |
return classAsObj | |
}, {}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sleep = (ms = 0) => new Promise(r => setTimeout(r, ms)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Only take the specified fields out of the object | |
*/ | |
const pick = (o, ...fields) => | |
fields.reduce((acc, x) => { | |
if ((o || {}).hasOwnProperty(x)) { | |
acc[x] = o[x]; | |
} | |
return acc; | |
}, {}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react' | |
/** | |
* Examples of Reusable Custom Hooks | |
* - useLodash https://github.com/chantastic/use-lodash | |
* - useEvents https://github.com/sandiiarov/use-events | |
* - list of hooks https://github.com/streamich/react-use | |
* - awesome hooks https://github.com/rehooks/awesome-react-hooks | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* this_is_snake_case | |
* thisIsCamelCase | |
* this-is-cabob-case | |
*/ | |
const camelToSnakeCase = w => w.replace(/([A-Z])/g, l => '_' + l.toLowerCase()) | |
const toCamel = s => s.replace(/(\-[a-z])/g, l => l.toUpperCase().replace('-','')) | |
const cabobToCamelCase = s => s.replace(/([A-Z])/g, l => "-"+l.toLowerCase()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Handles special characters too | |
*/ | |
const capitalize = w => w.toLowerCase().replace(/(?:^|\s)\S/g, l => l.toUpperCase()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// recursive | |
const isPalindrome = str => { | |
if (str.length === 0 || str.length === 1) return true | |
if (str[0] === str[str.length - 1]) return isPalindrome(str.slice(1, str.length - 1)) | |
return false | |
} | |
// efficiently in O(n) time | |
const isPalindrome2 = str => { | |
var half = Math.floor(str.length / 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isLeapYear = year => new Date(year,1,29).getDate() === 29 |