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 toTanginaMoCase = (str: string): string => { | |
// Convert snake case to title case | |
return str.split('_') | |
.map(str => str.charAt(0).toUpperCase() + str.substr(1)) | |
.join('') | |
.replace(/([A-Z])/g, ' $1') | |
.trim() | |
} |
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
var provinces = require('philippines/provinces') | |
var cities = require('philippines/cities') | |
function getCitiesByRegion(region) { | |
// Provinces under that specific region | |
var provinces = provinces.filter(province => province.region === region) | |
return provinces | |
// Append cities to the provinces under that specific region | |
// [{ name: 'Batanes}, region: 'II', key: 'BTN' }] -> [{ name: 'Batanes}, region: 'II', key: 'BTN', cities: ['Basco', ...] }] |
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 } from 'react' | |
const useLocalStorageState = <T>(key: string, defaultValue?: T): [T, (value: T) => void] => { | |
const [state, internalSetState] = useState<T>(() => { | |
try { | |
const value = localStorage.getItem(key) | |
if (value) return JSON.parse(value) | |
} catch (e) { | |
console.error(e) | |
} |
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 React, { useContext, useState, useEffect } from 'react' | |
interface NavigationItem { | |
back: string | |
title: string | |
} | |
interface ContextType { | |
active: NavigationItem | null | |
setActive: (active: NavigationItem | null) => void |
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
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
list := []int{38, 27, 24, 56, -16, 12, 32, -3, 16, 11, 15, 25, 29} | |
fmt.Printf("Original: %v\n", mergeSort(list)) | |
fmt.Printf("Post-Merge Sort: %v\n", merged) |
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 array = [38, 27, 24, 56, 12, 32, 16, 11, 15, 25, 29]; | |
console.log(mergeSort(array)); |
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 React, { useContext } from 'react' | |
import { useUser } from 'contexts/User' | |
export default function Page() { | |
const user = useUser(context) | |
return ( | |
<div>Your name is {user.name}</div> | |
) | |
} |
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
declare module 'react-input-slider' { | |
export interface SliderValue { | |
x: number | |
y: number | |
} | |
export interface SliderProps { | |
axis?: 'x' | 'y' | 'xy' | |
x?: number | |
y?: number |
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 * as React from 'react' | |
import { useState, useRef } from 'react' | |
import Slider, { SliderValue } from 'react-input-slider' | |
type Style = { [key: string]: any } | |
interface Props { | |
value: number | |
min: number | |
max: number |
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 log = (label, value) => { | |
console.log(label, value) | |
return value | |
} |