Skip to content

Instantly share code, notes, and snippets.

@OO00O0O
OO00O0O / translit.php
Last active May 18, 2016 12:35
Multi lang slug generator with simple translit
<?php
public static function slug($str, $replace = [], $delimiter = '-')
{
if(count($replace)) {
$str = str_replace($replace, ' ', $str);
}
setlocale(LC_CTYPE, 'en_US.UTF8');
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
@OO00O0O
OO00O0O / gist:9e70c63c6a96a10230441b75115a3303
Created October 25, 2016 14:27 — forked from farico/gist:3938084
Linksniavimas LT vardu
<?php
/**
* Lietuviškų vardų linksniai.
*
* @author Maug Lee <mauglee@gmail.com>
* @copyright Copyleft (ↄ) 2011, Maug Lee
* @version 0.3
* @package Vardai
*/
@OO00O0O
OO00O0O / alphaID.php
Created December 20, 2016 09:32
Create Youtube-Like IDs With PHP/Python/Javascript/Java/SQL: http://kvz.io/blog/2009/06/10/create-short-ids-with-php-like-youtube-or-tinyurl/
<?php
/**
* Translates a number to a short alhanumeric version
*
* Translated any number up to 9007199254740992
* to a shorter version in letters e.g.:
* 9007199254740989 --> PpQXn7COf
*
* specifiying the second argument true, it will
* translate back e.g.:
@OO00O0O
OO00O0O / di.php
Last active January 28, 2021 09:17
PHP single function dependency injection
<?php declare(strict_types=1);
if (PHP_VERSION_ID < 80000) { die('only php 8'); }
/**
* Single function dependency injection POC
*/
interface Inter {}
class A { public function __construct(private int $id) {} }
class E { public function __construct(private int $id) {} }
class B { public function __construct(private A|E $a) {} }
@OO00O0O
OO00O0O / router.php
Created October 17, 2021 06:28
Simple regexp router
<?php declare(strict_types=1);
$routes = [
['GET /(?<something_file>[a-z][a-z0-9]{8}\.[a-z0-9]{3,4})', '...meta...'],
['GET /(?<ok>what|na)', '...meta...'],
['POST /', '...meta...'],
];
$regexp = implode('|', array_map( // could be cached
static function (int $index, array $values) {
<?php $z='█';$x=' ';$r=10;$s=2.5;$d=10;$t=0.0;$_=pi();$w=exec('tput cols');$h=exec('tput lines');
$c=[abs($w/2),abs($h/2)];function d(&$m,$a,$b,$c,$f){$n=$b[0]-$a[0];$e=$b[1]-$a[1];$s=
max(abs($n),abs($e));$n/=$s;$e/=$s;$x=$a[0];$y=$a[1];for($i=0;$i<=$s;$i++){$m[round($y)]
[round($x)]="\033[0;".($f+30).";40m$c\033[0;0m";$x+=$n;$y+=$e;}}while(true){$m=array_fill(
0,$h,array_fill(0,$w,$x));$j=$u=[cos($t)*$r+$c[0],sin($t)*$r/$s+$d/2+$c[1]];$k=$i=[cos(
$t+$_/2)*$r+$c[0],sin($t+$_/2)*$r/$s+$d/2+$c[1]];$l=$o=[cos($t+$_)*$r+$c[0],sin($t+$_)*
$r/$s+$d/2+$c[1]];$n=$p=[cos($t+3*$_/2)*$r+$c[0],sin($t+3*$_/2)*$r/$s+$d/2+$c[1]];$j[1]-=
$d;$k[1]-=$d;$l[1]-=$d;$n[1]-= $d;d($m,$u,$i,$z,1);d($m,$i,$o,$z,2);d($m,$o,$p,$z,3);
d($m,$p,$u,$z,4);d($m,$u,$j,$z,1);d($m,$i,$k,$z,2);d($m,$o,$l,$z,3);d($m,$p,$n,$z,4);
d($m,$j,$k,$z,1);d($m,$k,$l,$z,2);d($m,$l,$n,$z,3);d($m,$n,$j,$z,4);usleep(100000);$t+=