Skip to content

Instantly share code, notes, and snippets.

View hanipcode's full-sized avatar
🎯
Focusing

Muhammad Hanif hanipcode

🎯
Focusing
View GitHub Profile
@hanipcode
hanipcode / coding-standards-draft.md
Created July 7, 2026 13:11 — forked from dmmulroy/coding-standards-draft.md
coding-standards-draft.md

TypeScript Coding Standards

These standards describe how to design and write TypeScript code in this codebase. They are especially intended for agents: before adding patterns, libraries, adapters, or abstractions, read the existing code and prefer the local convention unless it conflicts with the safety/correctness principles below.

Decision priority

When rules pull in different directions, use this order:

  1. Preserve correctness, safety, and debuggability.
  2. Follow established project architecture and conventions.
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) => {