Skip to content

Instantly share code, notes, and snippets.

View hanipcode's full-sized avatar
🎯
Focusing

Muhammad Hanif hanipcode

🎯
Focusing
View GitHub Profile
import { $Values } from "utility-types";
const LEVEL = {
info: "info",
debug: "debug",
warning: "warning",
error: "error",
} as const;
type LEVEL_TYPE = $Values<typeof LEVEL>;
@hanipcode
hanipcode / queries.js
Created December 29, 2023 11:26
mongodb shell date queries helper
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);
import p from 'immer';
interface CreateSliceOption {
name: string;
initialState: Record<string, unknown>;
reducers: Record<string, Function>;
}
const createKey = (name, key) => `${name}-reducer-${key}-action`;
@hanipcode
hanipcode / curr.js
Last active August 8, 2019 08:46 — forked from insanrizky/curr.js
Curr with K M B T
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];
class ListingCard extends React.Component {
state = {
favoriteListings : [],
}
async componentDidMount() {
const { listingId } = this.props;
const favoriteListings = await getData();
this.setState({ favoriteListings });
}
class ListingCard extends React.Component {
state = {
isFavorite: false,
favoriteListings : [],
}
async componentDidMount() {
const { listingId } = this.props;
const favoriteListings = await getData();
const isFavorite = favoriteListings.indexOf(listingId);
// 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) {
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) => {
@hanipcode
hanipcode / 1. main.css
Created August 16, 2018 04:56 — forked from EmranAhmed/1. main.css
CSS Responsive breakpoint, Media Query break point
/*==================================================
= Bootstrap 3 Media Queries =
==================================================*/
/*========== Mobile First Method ==========*/
/* Custom, iPhone Retina */
@media only screen and (min-width : 320px) {
}