Skip to content

Instantly share code, notes, and snippets.

View brianswisher's full-sized avatar

Brian Swisher brianswisher

View GitHub Profile
@brianswisher
brianswisher / countUniqueValues.js
Last active July 26, 2019 23:43
Count Unique Values
(()=>{
function countUniqueValues(sortedArray) {
const myArray = sortedArray.slice(0)
let count = 0
myArray.forEach((num, i) => {
const rightNum = myArray[i + 1]
if (myArray[count] !== rightNum) {
@brianswisher
brianswisher / dynamicRequire.js
Created July 16, 2019 00:18
Using dynamic require with JavaScript
((name)=>{
return fetch(`https://wzrd.in/bundle/${name}@latest/`)
.then(response => response.text())
.then(body => {
eval(body)
window[name] = require(name)
})
})('jquery').then(()=>{
const $ = jquery
@brianswisher
brianswisher / restoreValue.js
Last active July 12, 2019 13:49
Using form state & debounce with JavaScript
(() => {
const test = (result, expect) =>
`${result === expect && '✅' || '🔴'} ${expect}:${result}`
const mkRestore = (input, state) => {
return () => {
state.names.pop()
input.value = state.names[state.names.length - 1] || ''
}
}
@brianswisher
brianswisher / dynamicNestedObject.js
Created July 10, 2019 23:25
Easy testing with JavaScript
(()=>{
const test = (result, expect) =>
`${result === expect && '✅' || '🔴'} ${expect}:${result}`
function dynamicNestedObject (total, value) {
const result = {}
const keys = 'abcdefghijklmnopqrstuvwxyz'.substring(0, total).split('')
const lastIndex = keys.length - 1
keys.reduce((o, k, i) => {
sed -i -e 's/{{/_*/g' package.json && sed -i -e 's/}}/*_/g' package.json && yarn && rm package.json-e && git checkout package.json
/*eslint no-console: ["error", { allow: ["warn", "error"] }] */
@brianswisher
brianswisher / NIGHTLY_QUESTIONS.md
Created May 30, 2018 17:09
Nightly Questions
  • What will I make happen within five years? (ONE major goal)
  • What will I make happen within one year? (ONE major goal)
  • What will I make happen within 30 days? (ONE thing)
  • What will I make happen within seven days? (ONE thing)
  • What will I do to start this day positively? (Doing something other than what I usually do out of habit)
  • What must get done today that develops my main craft? (Daily work on a craft leads to mastery)
  • What three extra tasks must get done today if any? (Streamline your to-do list to what matters)
  • Who will I contact today to generate opportunities and good will? (Nourish your relationships)
  • What will I do today that scares me? (Keep me stretching, building confidence and character)
  • What will I do today to benefit my health?
@brianswisher
brianswisher / requestedUrl.js
Created November 14, 2017 23:04
Requested URL
var requestedUrl = req.protocol + '://' + req.get('Host') + req.url
@brianswisher
brianswisher / .editorconfig
Last active August 28, 2017 19:31
A static test drive for https://bl.ocks.org
# http://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 120
@brianswisher
brianswisher / wait.js
Created August 14, 2017 22:46
Wait w/ a promise
function wait (delay = 1000) {
return new Promise((resolve) => {
setTimeout(() => {
resolve()
}, delay)
})
}