10. 12. 2020
function versus(callable $first, callable $second, $repeat = 100000) {
$f = microtime(true);
foreach (range(0, $repeat) as $r) call_user_func($first);
$firstTimer = microtime(true) - $f;
$s = microtime(true);
foreach (range(0, $repeat) as $r) call_user_func($second);
$secondTimer = microtime(true) - $s;
printf(
'%s function is %.2f%% faster (%f vs %f)',
$firstTimer < $secondTimer ? 'First' : 'Second',
abs((($firstTimer - $secondTimer) / $firstTimer) * 100),
$firstTimer, $secondTimer
);
}
Example
versus(
function () {
$str = '!loremipsum';
return substr($str, 0, 1) === '!';
},
function () {
$str = '!loremipsum';
return $str[0] === '!';
}
);
Will print:
Second function is 36.72% faster (0.142766 vs 0.090349)
#PHP #Snippets
1. 12. 2020
Insert following code to functions.php
for debuging 404 page:
ini_set('error_reporting', -1);
ini_set('display_errors', 'On');
add_action(
'parse_request',
function (&$wp) {
global $wp_rewrite;
printf('<h2>rewrite rules</h2><pre>%s</pre>', var_export($wp_rewrite->wp_rewrite_rules(), true));
printf('<h2>permalink structure</h2><pre>%s</pre>', var_export($wp_rewrite->permalink_structure, true));
printf('<h2>page permastruct</h2><pre>%s</pre>', var_export($wp_rewrite->get_page_permastruct(), true));
printf('<h2>matched rule and query</h2><pre>%s</pre>', var_export($wp->matched_rule, true));
printf('<h2>matched query</h2><pre>%s</pre>', var_export($wp->matched_query, true));
printf('<h2>request</h2><pre>%s</pre>', var_export($wp->request, true));
global $wp_the_query;
printf('<h2>the query</h2><pre>%s</pre>', var_export($wp_the_query, true));
}
);
add_action(
'template_redirect',
function () {
global $wp_filter;
printf(
'<h2>template redirect filters</h2><pre>%s</pre>',
var_export($wp_filter[current_filter()], true)
);
}, 99999
);
add_filter(
'template_include',
function ($template) {
printf(
'<h2>template file selected</h2><pre>%s</pre>',
var_export($template, true)
);
exit();
}
);
#Wordpress #PHP
20. 11. 2020
First download macOS Big Sur From Apple with App Store. Quit installator with ⌘+q
, then create new empty volume:
sudo hdiutil create -o /tmp/BigSur -size 16384m -volname BigSur -layout SPUD -fs HFS+J
Mount new volume:
sudo hdiutil attach /tmp/BigSur.dmg -noverify -mountpoint /Volumes/BigSur
Create bootable dmg
and copy to new volume:
sudo /Applications/Install\ macOS\ Big\ Sur.app/Contents/Resources/createinstallmedia --volume /Volumes/BigSur --nointeraction
Eject installator:
hdiutil eject -force /Volumes/Install\ macOS\ Big\ Sur
Convert dmg
to cdr
file:
hdiutil convert /tmp/BigSur.dmg -format UDTO -o ~/Downloads/BigSur
Rename cdr
to iso
:
mv -v ~/Downloads/BigSur.cdr ~/Downloads/BigSur.iso
Delete original created dmg
file:
sudo rm -fv /tmp/BigSur.dmg
How to create a bootable installer for macOS
#macOS
12. 11. 2020
You can use ippfind command that finds services
registered with a DNS server or available through local devices. Its primary purpose is to find IPP printers
and show their URIs, show their current status, or run commands.
ippfind
Then you get local adress of printer (Internet Printing Protocol (IPP, RFC 2911)):
ipp://3036B5000000.local:XXX/ipp/print
then ping local address
ping 3036B5000000.local
and here we go
PING 3036B5000000.local (192.168.0.108): 56 data bytes
64 bytes from 192.168.0.108: icmp_seq=0 ttl=64 time=262.342 ms
64 bytes from 192.168.0.108: icmp_seq=1 ttl=64 time=285.290 ms
our printer has 192.168.0.108
#macOS