Skip to content

Instantly share code, notes, and snippets.

🤷‍♂
¯\_(ツ)_/¯

Lester Chan lesterchan

🤷‍♂
¯\_(ツ)_/¯
Block or report user

Report or block lesterchan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lesterchan
lesterchan / private_mode_detection.js
Created Nov 28, 2018
Private/Incognito Mode Detection For Browers
View private_mode_detection.js
function retry(isDone, next) {
var current_trial = 0, max_retry = 50, interval = 10, is_timeout = false;
var id = window.setInterval(
function() {
if (isDone()) {
window.clearInterval(id);
next(is_timeout);
}
if (current_trial++ > max_retry) {
window.clearInterval(id);
@lesterchan
lesterchan / fix_missed_scheduled_posts.php
Created Sep 14, 2017
Fix missed WordPress scheduled post by publishing it after it has been missed (PHP 7.1)
View fix_missed_scheduled_posts.php
<?php
/**
* Fix for missing scheduled post
*
* @param array $schedules Cron Schedules.
*
* @return array
*/
function lc_cron_schedules( array $schedules ) : array {
$schedules['lc_publish_missed_scheduled_posts'] = [
@lesterchan
lesterchan / plugin_deploy.sh
Last active Feb 3, 2016
WordPress Plugin Deploy From GitHub to SVN
View plugin_deploy.sh
#!/bin/bash
# paths
SRC_DIR=$(git rev-parse --show-toplevel)
DIR_NAME=$(basename $SRC_DIR)
#MSG=${1-'Deploying $DIR_NAME from GitHub'}
#BRANCH=${2-'trunk'}
MSG="Deploying $DIR_NAME from GitHub"
BRANCH="trunk"
DEST_DIR=~/svn/wordpress_plugins/$DIR_NAME/$BRANCH
@lesterchan
lesterchan / hhvm.conf
Created Apr 24, 2015
HHVM with PHP-FPM fallback
View hhvm.conf
location ~ \.(hh|php)$ {
proxy_intercept_errors on;
error_page 502 = @fallback;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
@lesterchan
lesterchan / wordpress_plugin_skeleton.php
Last active Sep 22, 2016
WordPress Plugin Skeleton
View wordpress_plugin_skeleton.php
<?php
/*
Plugin Name: Plugin name
Plugin URI: http://pluginurl.com
Description: Plugin description
Version: 1.0.0
Author: Plugin author
Author URI: http://pluginauthorurl.com
Text Domain: plugin-name
*/
@lesterchan
lesterchan / delete_wordpress_revisions.php
Last active Aug 29, 2015
Delete WordPress Revisions
View delete_wordpress_revisions.php
<?php
/**
* Delete revisions from WordPress
*/
define( 'WP_USE_THEMES', false );
if( ! empty( $_SERVER['WP_DIR'] ) ) {
require( $_SERVER['WP_DIR'] . '/wp-blog-header.php' );
} elseif( is_file( 'wp-blog-header.php' ) ) {
require( 'wp-blog-header.php' );
} else {
View social_media_colors.css
.color-pinterest {
color: #cb2027;
}
.color-facebook {
color: #3b5998;
}
.color-twitter {
color: #00aced;
}
.color-vimeo {
@lesterchan
lesterchan / get_social_links_share_count.md
Last active Jan 20, 2017
Get Social Links Share Count
View get_social_links_share_count.md
View ip_address.php
<?php
function get_ip() {
foreach ( array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
if ( array_key_exists( $key, $_SERVER ) === true ) {
foreach ( explode( ',', $_SERVER[$key] ) as $ip ) {
$ip = trim( $ip );
if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
return $ip;
}
}
@lesterchan
lesterchan / countries.php
Created Sep 22, 2014
Countries In PHP Array
View countries.php
<?php
$countries = array( 'Afghanistan', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegowina', 'Botswana', 'Bouvet Island', 'Brazil', 'British Indian Ocean Territory', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo', 'Congo, the Democratic Republic of the', 'Cook Islands', 'Costa Rica', 'Cote d\'Ivoire', 'Croatia (Hrvatska)', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Islan
You can’t perform that action at this time.