This file contains 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 './style.css'; | |
import Home from './views/Home'; | |
import Todo from './views/Todo'; | |
import TodoEdit from './views/TodoEdit'; | |
import NotFound from './views/NotFound'; | |
import Router, { RouteErrorProps, RouteProps, Routes } from './lib/router'; | |
function handleProtected(props: RouteProps): boolean { | |
return false; |
This file contains 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
// https://gist.github.com/nishanbajracharya/8fe38807b3ad074a7da2072c7b8e701b | |
function normalize(input = {}) { | |
var values = Array.isArray(input) ? input : Object.values(input); | |
return values.reduce((acc, value) => { | |
if (value.children) { | |
return { | |
...acc, | |
[value.id]: { |
This file contains 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
// DEFINE BASE_URL | |
// DEFINE refreshAccessToken, this should use `refreshInstance` instead of `instance` | |
/* | |
function refreshAccessToken() { | |
return refreshInstance | |
.post('token', { | |
refresToken: localStorage.getItem('refreshToken') | |
}) | |
... |
This file contains 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
function toKebabCase(string) { | |
return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase(); | |
} | |
function hash(string) { | |
var h = 0 | |
var i = 0; | |
if (string.length > 0) { | |
while (i < string.length) { |
This file contains 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
function preloadImages(srcs, onComplete = f => f) { | |
var imgArray = {}; | |
var imgErrorArray = {}; | |
var imageFailCount = 0; | |
var imageLoadedCount = 0; | |
srcs.forEach(function(src, index) { | |
imgArray[index] = null; | |
imgErrorArray[index] = null; |
This file contains 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
#!/bin/bash | |
repoURL=$1 | |
port=${2:-5000} | |
portInUse=$(lsof -t -i :$port) | |
if [ -z "$portInUse" ] | |
then | |
printf "Port $port available.\n\n" | |
else |
This file contains 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
var input = { | |
'1': { | |
id: 1, | |
name: 'John', | |
children: [{ | |
id: 2, | |
name: 'Sally' | |
}, | |
{ | |
id: 3, |
This file contains 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
// From this | |
var input = { | |
'1': { | |
id: 1, | |
name: 'John', | |
children: [ | |
{ id: 2, name: 'Sally' }, | |
{ id: 3, name: 'Mark', children: [{ id: 4, name: 'Harry' }] } | |
] | |
}, |
This file contains 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 animate = document.getElementById('animate'); | |
const btn = document.getElementById('btn'); | |
let enabled = false; | |
btn.onclick = function() { | |
if (enabled) { | |
enabled = false; | |
transition(animate, { |
This file contains 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
class Observer { | |
constructor(state) { | |
this.state = state; | |
this.subscribers = []; | |
} | |
get() { | |
return this.state; | |
} |
NewerOlder