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
@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, '&')
.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()

FX Reference

State

State

  • fx_get_state(string $key): mixed
  • fx_set_state(string $key, mixed $value): mixed
  • fx_no_state(string $key): bool
  • fx_state(string $key, mixed $default_value = NULL): mixed
function patch (current, next) {
if (current.isEqualNode(next)) {
return
}
if (current.nodeName !== next.nodeName) {
current.parentNode.replaceChild(current, next)
return
}
if (current.nodeType === 3) {
if (current.data !== next.data) {
.range {
position: relative;
height: 24px;
display: flex;
flex-direction: column;
justify-content: center;
cursor: default;
user-select: none;
}
.range:before {
<?php
$file = 'path-to-file';
$size = filesize($file);
$start = 0;
$end = $size - 1;
if (preg_match('/bytes=(\d+)-(\d*)/i', $_SERVER['HTTP_RANGE'] ?? '', $matches)) {
$start = $matches[1];
if (!empty($matches[2])) {
$end = $matches[2];
}