Skip to content

Instantly share code, notes, and snippets.

View allenhwkim's full-sized avatar

Allen Kim allenhwkim

View GitHub Profile
@allenhwkim
allenhwkim / polygon-area.js
Created March 17, 2025 12:49
calculate polygon area in square meters
function calculatePolygonArea(coordinates) {
// Check if the polygon is closed (first and last points should match)
const first = coordinates[0];
const last = coordinates[coordinates.length - 1];
if (first[0] !== last[0] || first[1] !== last[1]) {
coordinates.push([...first]); // Close the polygon if not already closed
}
// Calculate average latitude for longitude scaling
const latitudes = coordinates.map(coord => coord[1]);
@allenhwkim
allenhwkim / Draggable.css
Created February 24, 2025 13:53
React Draggable
.draggable-console {
z-index: 4;
position: absolute;
background: #FFF;
border: 1px solid #ccc;
font-size: .75rem;
&.collapsed {
> :not(.title) /* .console */ {
display: none;
@allenhwkim
allenhwkim / DialogModal.scss
Created February 24, 2025 13:51
React Dialog
.dialog-modal {
border: 0;
border-radius: 0.5rem;
width: 50%;
height: 75%;
padding: 0;
overflow: auto;
background-color: #f6f6f6;
&::backdrop {
@allenhwkim
allenhwkim / undo-redo.mjs
Created January 26, 2025 04:33
UndoRedo
import structuredClone from "@ungap/structured-clone";
export const UndoRedo = {
debounceMs: 300,
timeout: 0,
undoStack: [],
redoStack: [],
reset(item) {
@allenhwkim
allenhwkim / grapesjs-plugin-grid.js
Created January 3, 2025 01:00
grapesjs-plugin-grid
! function(t, e) {
'object' == typeof exports && 'object' == typeof module ? module.exports = e() : 'function' == typeof define && define.amd ? define([], e) : 'object' == typeof exports ? exports["grapesjs-plugin-grid"] = e() : t["grapesjs-plugin-grid"] = e()
}('undefined' != typeof globalThis ? globalThis : 'undefined' != typeof window ? window : this, (() => (() => {
"use strict";
var t = {
d: (e, n) => {
for (var o in n) t.o(n, o) && !t.o(e, o) && Object.defineProperty(e, o, {
enumerable: !0,
get: n[o]
})
@allenhwkim
allenhwkim / states.json
Created December 30, 2024 19:36
states.json
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@allenhwkim
allenhwkim / countries.json
Created December 30, 2024 19:21
List of countries
{
"countries": [
{
"name": "Afghanistan",
"code": "AF"
},
{
"name": "Åland Islands",
"code": "AX"
},
@allenhwkim
allenhwkim / formatDate.js
Last active December 22, 2024 21:56
Simple date format function
// yyyy - full uyear, e.g. 1969
// mm - two digit month, e.g. 01, 12
// mmm - e.g. Jan, Feb, Mar
// dd - two digit date e.g. 01, 31
// ddd - 1st, 2nd 21st
// www - e.g. Mon, Tue, Wed...
function formatDate(date, format = 'yyyy-mm-dd') { // mm/dd/yyyy, www MMM DDD YYYY
const day = date.getDate();
const weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
@allenhwkim
allenhwkim / Instruction.md
Created October 12, 2024 16:54
Google reCAPTCHA v3 server/browser
@allenhwkim
allenhwkim / form-validation.html
Created October 1, 2024 21:38
form controls and validation
<!DOCTYPE html>
<html lang="en">
<head>
<title>Form controls and validation</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
</head>
<body>
<form onsubmit="handleSubmit(event)" noValidate> <!-- noValidate -->