A Pen by Muhammad Hanif on CodePen.
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 { $Values } from "utility-types"; | |
const LEVEL = { | |
info: "info", | |
debug: "debug", | |
warning: "warning", | |
error: "error", | |
} as const; | |
type LEVEL_TYPE = $Values<typeof LEVEL>; |
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 beginingOfDay = (options = {}) => { | |
const { date = new Date(), timeZone } = options; | |
const parts = Intl.DateTimeFormat("en-US", { | |
timeZone, | |
hourCycle: "h23", | |
hour: "numeric", | |
minute: "numeric", | |
second: "numeric", | |
}).formatToParts(date); | |
const hour = parseInt(parts.find((i) => i.type === "hour").value); |
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 p from 'immer'; | |
interface CreateSliceOption { | |
name: string; | |
initialState: Record<string, unknown>; | |
reducers: Record<string, Function>; | |
} | |
const createKey = (name, key) => `${name}-reducer-${key}-action`; |
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 React, { Component } from 'react'; | |
const SI_SYMBOL = ["", "k", "M", "G", "T", "P", "E"]; | |
function abbreviateNumber(number){ | |
const tier = Math.log10(number) / 3 | 0; | |
if(tier == 0) return number; | |
const suffix = SI_SYMBOL[tier]; |
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 ListingCard extends React.Component { | |
state = { | |
favoriteListings : [], | |
} | |
async componentDidMount() { | |
const { listingId } = this.props; | |
const favoriteListings = await getData(); | |
this.setState({ favoriteListings }); | |
} |
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 ListingCard extends React.Component { | |
state = { | |
isFavorite: false, | |
favoriteListings : [], | |
} | |
async componentDidMount() { | |
const { listingId } = this.props; | |
const favoriteListings = await getData(); | |
const isFavorite = favoriteListings.indexOf(listingId); |
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
// first we need to know is the array sorted | |
// the array can be sorted both ascending and descending | |
// can we check both at the same time ? | |
// first lets just check if they're sorted. | |
function isArraySorted(array) { | |
let isSortedDescending = true; | |
let isSortedAscending = true; | |
// descending | |
for (let i = 0; i < array.length; i = i + 1) { |
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 deleteAfterHelper = (apiGetUser, otherRouteApiFunc, otherRouteApiParam) => { | |
return new Promise((resolve, reject) => { | |
// TODOS: Add error exception using reject (bisa ditambah sendiri) | |
apiGetUser().then((data) => { | |
const { userId } = data; | |
const finalParam = { | |
id: userId, | |
...otherRouteApiParam, | |
}; | |
otherRouteApiFunc().then((otherApiData) => { |
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
/*================================================== | |
= Bootstrap 3 Media Queries = | |
==================================================*/ | |
/*========== Mobile First Method ==========*/ | |
/* Custom, iPhone Retina */ | |
@media only screen and (min-width : 320px) { | |
} |
NewerOlder