Skip to content

Instantly share code, notes, and snippets.

View ik5's full-sized avatar
🎯
Focusing

ik5 ik5

🎯
Focusing
View GitHub Profile
@ik5
ik5 / read_stdin.php
Created October 24, 2021 16:40
example on reading from stdin in php
<?php
while (!feof(STDIN)) {
$f = fgets(STDIN);
if ($f) {
echo ">> $f\n";
}
}
@ik5
ik5 / notify_watch.php
Created October 24, 2021 16:52
PECL inotify example for close_write on watch directory
<?php
$fd = inotify_init();
$watch_descriptor = inotify_add_watch($fd, './watch', IN_CLOSE_WRITE);
while (true) {
$events = inotify_read($fd);
foreach ($events as $event) {
@ik5
ik5 / prefix_function.sql
Created January 6, 2022 07:10
example on how to use postgresql to find the biggest prefix from content at a table
CREATE OR REPLACE FUNCTION public.prefixes(character varying) RETURNS character varying[]
LANGUAGE sql IMMUTABLE
AS $_$
SELECT ARRAY(SELECT substring($1 FROM 1 FOR i)
FROM generate_series(1, GREATEST(length($1))) g(i))::varchar[];
$_$
SELECT MAX(prefix) FROM MY_TABLE WHERE prefix=ANY(content);
@ik5
ik5 / lpa_regex_parsing.go
Last active April 20, 2025 11:52
LPA (Activation Code) string is the QR code you scan for provision eSIM to your telephone. The following code parse the string to it's elements based on GSMA standard.
package main
// go play with my original code: https://go.dev/play/p/dt8WFHM1E8d
import (
"fmt"
"regexp"
)
var validLPA = []string{