Skip to content

Instantly share code, notes, and snippets.

View audinue's full-sized avatar

Audi Nugraha audinue

  • Surabaya, Jawa Timur, Indonesia
View GitHub Profile
const changeTimeZone = (date: Date, timeZone: string) =>
new Date(
date.getTime() -
(date.getTime() -
new Date(date.toLocaleString("en-US", { timeZone })).getTime())
);
const dateTimeLocalValue = (date: Date) => {
const pad = (value: number) => value.toString().padStart(2, "0");
return (
{
"configurations": [
{
"name": "dev",
"request": "launch",
"runtimeExecutable": "pnpm",
"runtimeArgs": ["vite", "--host", "--open"],
"type": "node"
}
]
@audinue
audinue / sw.html
Last active October 31, 2024 08:53
Minimal service worker
<script>
navigator.serviceWorker.register('/sw.js').then(() => history.go(0))
</script>
@audinue
audinue / index.html
Last active August 31, 2024 19:20
Random path generator
<script>
var width = 5;
var height = 5;
var length = 10;
var possible_directions = [
[0, -1, "&uarr;"], // up
[0, 1, "&darr;"], // down
[-1, 0, "&larr;"], // left
[1, 0, "&rarr;"], // right
@audinue
audinue / demo.js
Created June 14, 2024 20:35
Restore selection after changing the innerHTML (DOM diffing alternative)
var html = function (text) {
return text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;')
}
var userName = 'John'
<?php
class Pluralize
{
function pluralize($word)
{
return $this->replaceWord(
$word,
$this->irregularSingles,
$this->irregularPlurals,
@audinue
audinue / runtime.php
Created May 31, 2024 16:00
local state for immediate stuff
<?php
function create_group($symbols, $prefix)
{
return (object) [
'tag' => 'group',
'symbols' => $symbols,
'prefix' => $prefix,
'key' => 0,
'used' => []
@audinue
audinue / example.js
Created May 16, 2024 05:22
Immediate mode DOM diffing (a.k.a. incremental DOM). Applicable to native platforms (WinForms, Android)
import { patch, begin, end, text } from "./immediate.js";
var count = 0;
function tick(event) {
if (event.type === "click") {
if (event.target.id === "increment") {
count++;
} else if (event.target.id === "decrement") {
count--;
<?php
namespace tiny_blade;
function _replace(string $template): string
{
// @endif
$template = preg_replace('/^\s*@(end.+?)\s*$/m', '<?php $1 ?>', $template);
// @if ($foo)
$template = preg_replace('/^\s*@(.+?)\s*$/m', '<?php $1: ?>', $template);
<?php
/**
* @method static Tag a()
* @method static Tag audio()
* @method static Tag body()
* @method static Tag br()
* @method static Tag button()
* @method static Tag div()
* @method static Tag form()