Skip to content

Instantly share code, notes, and snippets.

View ilhamgusti's full-sized avatar
👀
whoopss

ilhamgusti ilhamgusti

👀
whoopss
View GitHub Profile
@ilhamgusti
ilhamgusti / useForm.js
Created January 7, 2022 15:43
hooks for handle form input
import { useState } from "react";
function getInputOnChange(setValue) {
return (val) => {
if (!val) {
setValue(val);
} else if (typeof val === "function") {
setValue(val);
} else if (typeof val === "object" && "nativeEvent" in val) {
const { currentTarget } = val;
version: "3.3"
services:
traefik:
image: traefik
restart: always
container_name: traefik
ports:
- 80:80
- 443:443
@ilhamgusti
ilhamgusti / docker-compose.yml
Created November 2, 2021 02:55 — forked from Mau5Machine/docker-compose.yml
Traefik Configuration and Setup
version: "3.3"
services:
################################################
#### Traefik Proxy Setup #####
###############################################
traefik:
image: traefik:v2.0
restart: always
@ilhamgusti
ilhamgusti / dynamicsubdomain.example.conf
Created May 21, 2021 10:39
dynamicsubdomain.example.conf
server {
listen *:80;
server_name example.com *.example.com;
set $subdomain "";
if ($host ~ ^(.*)\.example\.com$) {
set $subdomain $1;
}
location / {
@ilhamgusti
ilhamgusti / isOverflowingElement.js
Created March 31, 2021 02:53
detect if element is overflow width (can check if element state is scrollable or not)
function isOverflowingElement(element) {
return (element.scrollWidth > element.offsetWidth);
}
@ilhamgusti
ilhamgusti / hardReloadKeypressSimulate.js
Created March 9, 2021 02:48
simulate hard reload keypress
function shift_f5_hard_reload() {
let evt = new KeyboardEvent("keydown", {
shiftKey: true,
key: "f5",
keyCode: 116
});
document.dispatchEvent(evt);
}
/**
*
* @param map Map data
* @param searchValue value
*/
export function getByValue(map: any[], searchValue: any): any {
for (const [key, value] of map.entries()) {
if (value === searchValue) return key;
}
}
/**
* Helper to produce an array of enum values.
* @param enumeration Enumeration object.
*/
export function enumToArray<T, G extends keyof T = keyof T>(enumeration: T): T[G][] {
const enumVals = Object.values(enumeration);
return enumVals.slice(enumVals.length / 2, enumVals.length) as T[G][];
}
@ilhamgusti
ilhamgusti / strdotReference.js
Created February 19, 2021 08:49
javascript string dot notation into object reference
function index(obj,is, value) {
if (typeof is == 'string')
return index(obj,is.split('.'), value);
else if (is.length==1 && value!==undefined)
return obj[is[0]] = value;
else if (is.length==0)
return obj;
else
return index(obj[is[0]],is.slice(1), value);
}
@ilhamgusti
ilhamgusti / useModal.js
Created February 10, 2021 02:33
use modal with data
import React from 'react';
export const useModal = () => {
const [data, setData] = React.useState({});
const [activeModal, setActiveModal] = React.useState('');
const handleModalOpen = React.useCallback(
({ type, index, dataSource }) => (e) => {
setData(dataSource);
setActiveModal(type);
},