Skip to content

Instantly share code, notes, and snippets.

View kn007's full-sized avatar
:octocat:
I may be slow to respond.

Karl Chen kn007

:octocat:
I may be slow to respond.
View GitHub Profile
@kn007
kn007 / cwebp.lua
Created January 8, 2019 23:26
Add convert image to webp support for nginx
--------------------------- Function ---------------------------------
function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
------------------------------------------------------------------------
if ngx ~= nil then
@kn007
kn007 / test.php
Last active December 11, 2017 12:17
get EXTENSION performance: preg_match vs pathinfo
<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
@kn007
kn007 / test.php
Last active February 26, 2021 07:46
performance: mt_rand vs openssl_random_pseudo_bytes vs random_bytes vs uniqid vs uuid
<?php
define('LOOP_COUNT',100000);
function create_uuid_v4(){
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),