Skip to content

Instantly share code, notes, and snippets.

View nawawi's full-sized avatar

Nawawi Jamili nawawi

View GitHub Profile
@nawawi
nawawi / PseudoCrypt.php
Last active March 1, 2023 00:43 — forked from ethanpil/gist:94455f8de76671aa9024
PseudoCrypt.php
<?php
/**
* Reference/source: http://stackoverflow.com/a/1464155/933782
*
* I want a short alphanumeric hash that’s unique and who’s sequence is difficult to deduce.
* I could run it out to md5 and trim the first n chars but that’s not going to be very unique.
* Storing a truncated checksum in a unique field means that the frequency of collisions will increase
* geometrically as the number of unique keys for a base 62 encoded integer approaches 62^n.
* I’d rather do it right than code myself a timebomb. So I came up with this.
*
@nawawi
nawawi / pllstrings.php
Created June 1, 2021 14:29 — forked from davidwebca/pllstrings.php
Translate regular gettext and underscore functions with Polylang's strings
<?php
add_filter('gettext', function($translation, $text, $domain) {
if(is_admin()) {
return $translation;
}
if($domain == 'mythemedomain') {
if(function_exists('icl_register_string')){
$slug = sanitize_title($text);
icl_register_string($domain, $slug, $text);
@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
--------------------------------------------------
@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',
@nawawi
nawawi / gist:8a328a51ba115d6405a01e52a4f98df3
Created March 21, 2020 03:10 — forked from danielestevez/gist:2044589
GIT Commit to an existing Tag
1) Create a branch with the tag
git branch {tagname}-branch {tagname}
git checkout {tagname}-branch
2) Include the fix manually if it's just a change ....
git add .
git ci -m "Fix included"
or cherry-pick the commit, whatever is easier
git cherry-pick {num_commit}
@nawawi
nawawi / redis_key_sizes.sh
Created February 12, 2020 12:03 — forked from epicserve/redis_key_sizes.sh
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
@nawawi
nawawi / .htaccess
Created May 18, 2019 18:10 — forked from seoagentur-hamburg/.htaccess
UPDATE 2019: Perfect .htaccess file for highspeed and security. You can use it for every WordPress-Website without problems. Highspeed and Security - testet on hundreds of Websites. If you are using a WordPress Multisite, change the last part of this file.
########################################################################
# OPTIMAL .htaccess FILE FOR SPEED AND SECURITY @Version 2019
# ----------------------------------------------------------------------
# @Author: Andreas Hecht
# @Author URI: https://andreas-hecht.com
# License: GNU General Public License v2 or later
# License URI: http://www.gnu.org/licenses/gpl-2.0.html
########################################################################
@nawawi
nawawi / gist:3cbb9051f62abbfb393faa224e4d5144
Created April 2, 2019 17:55 — forked from joshuabaker/gist:313648
Get all images in a HTML string
<?php
/**
* Returns all img tags in a HTML string with the option to include img tag attributes
*
* @author Joshua Baker
*
* @example $post_images[0]->html = <img src="example.jpg">
* $post_images[0]->attr->width = 500
*
@nawawi
nawawi / AppleImages.html
Created February 10, 2018 16:05 — forked from js62789/AppleImages.html
A list of apple touch icons and apple touch startup images
<!-- For iPad with high-resolution Retina display running iOS ≥ 7: -->
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="apple-touch-icon-152x152-precomposed.png">
<!-- For iPad with high-resolution Retina display running iOS ≤ 6: -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="apple-touch-icon-144x144-precomposed.png">
<!-- For iPhone with high-resolution Retina display running iOS ≥ 7: -->
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="apple-touch-icon-120x120-precomposed.png">
<!-- For iPhone with high-resolution Retina display running iOS ≤ 6: -->
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-114x114-precomposed.png">
<!-- For the iPad mini and the first- and second-generation iPad on iOS ≥ 7: -->
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="apple-touch-icon-76x76-precomposed.png">