Skip to content

Instantly share code, notes, and snippets.

View nawawi's full-sized avatar

Nawawi Jamili nawawi

View GitHub Profile
# apache
Header set Referrer-Policy strict-origin-when-cross-origin
Header set Content-Security-Policy 'report-uri /csp-report-parser;'
Header set Feature-Policy "payment 'self'; sync-xhr 'self' https://iszuddinismail.com"
Header set Permissions-Policy "payment=(self),sync-xhr=(self 'https://iszuddinismail.com')"
# nginx
# rc letak dalam etc/nginx-rc/extra.d/[APPNAME].headers.0.conf
add_header Content-Security-Policy "report-uri /csp-report-parser";
add_header Referrer-Policy "strict-origin-when-cross-origin";
@nawawi
nawawi / serializetest
Created December 1, 2020 00:03 — forked from bwg/serializetest
testing serialize vs. json_encode vs. var_export vs. msgpack_pack
PHP Version 5.4.30
--------------------------------------------------
Testing 10 item array over 1,000 iterations:
serialize 2.1979808807373 ms
json_encode 1.3420581817627 ms
var_export 1.9409656524658 ms
msgpack_pack 1.5850067138672 ms
--------------------------------------------------
# 19012018: awie
# server ram 4GB, db setting for 2GB
[mysqld]
user=mysql
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
local-infile=0
innodb_file_per_table=1
skip-networking
skip-name-resolve
# analyze all dbs and tables everyday 3:30am
30 3 * * * root /usr/bin/mysqlcheck --all-in-1 -Aa --auto-repair --compress -uDBUSER -pDBPASS &>/dev/null
# optimize all dbs and tables everyday 4:30am
30 4 * * * root /usr/bin/mysqlcheck --all-in-1 -Ao --auto-repair --compress -uDBUSER -pDBPASS &>/dev/null
; Enable Zend OPcache extension module
zend_extension=opcache
; Determines if Zend OPCache is enabled
opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
;opcache.enable_cli=0
; The OPcache shared memory storage size.
<?php
// 29-Oct-2020
// Docket Cache Drop-In wrapper for DOCKET_CACHE_CONTENT_PATH constant
if (!\defined('ABSPATH')) {
return;
}
if (!\defined('DOCKET_CACHE_DROPINO_ALTERNATIVE') || !DOCKET_CACHE_DROPINO_ALTERNATIVE) {
return;
@nawawi
nawawi / docketcache-mu.php
Created August 8, 2020 16:39
REST API restricted to authenticated users abd Accept basic authentication
<?php
/**
* Docket Cache.
*
* @author Nawawi Jamili
* @license MIT
*
* @see https://github.com/nawawi/docket-cache
*/
@nawawi
nawawi / override_wp_user_query.php
Created July 8, 2020 21:52 — forked from bosunolanrewaju/override_wp_user_query.php
How to remove the slow SQL_CALC_FOUND_ROWS from WP_User_Query and replace with standard COUNT() which is more performant.
<?php
/**
* Before sql query is generated, intercept `query_vars` and set `count_total` to false
* to prevent `SQL_CALC_FOUND_ROWS` from being added to the sql query.
* Also set our new `query_vars` attribute to true to track if count is required.
*/
add_action( 'pre_get_users', function($wpq) {
if ( isset($wpq->query_vars['count_total'] ) && $wpq->query_vars['count_total'] ) {
$wpq->query_vars['count_total'] = false;
$wpq->query_vars['run_count'] = true;
<?php
/**
* Plugin Name: YOUR PLUGIN NAME
*/
include( dirname( __FILE__ ) . '/lib/requirements-check.php' );
$your_plugin_requirements_check = new YOUR_PREFIX_Requirements_Check( array(
'title' => 'YOUR PLUGIN NAME',
'php' => '5.4',
<?php
// https://stackoverflow.com/a/41634468
$file = new SplFileObject("/path/to/file");
$file->seek(PHP_INT_MAX); // cheap trick to seek to EoF
$total_lines = $file->key(); // last line number
// output the last twenty lines
$reader = new LimitIterator($file, $total_lines - 20);
foreach ($reader as $line) {