Skip to content

Instantly share code, notes, and snippets.

View kenmueller's full-sized avatar
💻
Guess

Ken Mueller kenmueller

💻
Guess
View GitHub Profile
@kenmueller
kenmueller / store.js
Last active February 27, 2020 18:12
Persistent store on the web, modeled after Firebase Firestore
/*
* - Access a collection
* store.collection('users')
*
* - Access a document
* store.collection('users').document('abc')
* store.document('users/abc')
*
* - Get all the documents in a collection
* store.collection('users').documents() // Forced to reload documents
@kenmueller
kenmueller / web-framework.js
Created December 9, 2019 04:16
Web framework using state
const __internal_VALID_ELEMENT_ID_CHARACTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
const __internal_ELEMENT_ID_LENGTH = 36
let __internal_elements = () => []
const __internal_generateElementId = () =>
[...Array(__internal_ELEMENT_ID_LENGTH)]
.map(() =>
__internal_VALID_ELEMENT_ID_CHARACTERS.charAt(
Math.floor(Math.random() * __internal_VALID_ELEMENT_ID_CHARACTERS.length)
@kenmueller
kenmueller / backup.sh
Created June 19, 2019 03:12
Bash script for backing up git repositories
# Before copying, replace GITHUB_USERNAME shown below with your GitHub username
# Copy this into your .bash_profile found in ~/
# When you're inside of a git repo, call "backup" without any arguments to back up the current git repo
# Even when you are outside of a git repo, call "backup REPO_NAME", for example "backup typescript"
function backup() {
if [ -z "$1" ]
then
cloneUrl=$(git config --get remote.origin.url)
else
@kenmueller
kenmueller / newId.js
Last active May 31, 2019 02:55
Creates a random ID with a specified length
const newId = length =>
[...Array(length)].map(_i => (~~(Math.random() * 36)).toString(36)).join('')
function newId(length) {
return [...Array(length)].map(_i => (~~(Math.random() * 36)).toString(36)).join('')
}
@kenmueller
kenmueller / competition-problem.js
Created May 30, 2019 17:37
Competition problem used in a Microsoft interview in JavaScript
const duplicate = arr => {
const ordered = Array(arr.length).fill(false)
for (let i = 0; i < arr.length; i++) {
const element = arr[i]
if (ordered[element])
return element
ordered[element] = true
}
}