Skip to content

Instantly share code, notes, and snippets.

View lesterchan's full-sized avatar
🥞
Full Stack Engineer

Lester Chan lesterchan

🥞
Full Stack Engineer
View GitHub Profile
@lesterchan
lesterchan / private_mode_detection.js
Created November 28, 2018 09:24
Private/Incognito Mode Detection For Browers
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 September 14, 2017 04:58
Fix missed WordPress scheduled post by publishing it after it has been missed (PHP 7.1)
<?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 / get_social_links_share_count.md
Last active January 20, 2017 21:45
Get Social Links Share Count
@lesterchan
lesterchan / wordpress_plugin_skeleton.php
Last active September 22, 2016 13:26
WordPress Plugin Skeleton
<?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 / plugin_deploy.sh
Last active February 3, 2016 09:47
WordPress Plugin Deploy From GitHub to SVN
#!/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 / send_exception_to_ga.js
Created October 16, 2013 00:38
Use Google Analytics (GA) events (https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide) to track & log JavaScript exceptions
Utility.send_exception_to_ga = function()
{
if(true || window.settings && window.settings.debug)
{
return;
}
var gOldOnError = window.onerror;
window.onerror = function(message, url, line) {
var e_obj = [
"_trackEvent"
@lesterchan
lesterchan / 2_missing_numbers.php
Created July 5, 2013 09:57
You have a array of a million integers. They are ordered 1,2,3,4,5... all the way to 1,000,000. I shuffle the array and I remove two of the numbers. Write a function (in any language of your choice) that takes the array of 999,998 numbers and efficiently determines which two numbers between 1 and 1,000,000 have been removed.
<?php
// Max Integer
define('MAX', 1000000);
// Create An Array Till MAX
$original = range(1, MAX);
// Shuffle The Array While Preserving Keys
$shuffle = $original;
shuffle_assoc($shuffle);
@lesterchan
lesterchan / wp-includes_user.php
Created June 22, 2013 03:09
WordPress hacking attempt at getting password written to wp-content/plugins/.htaccess
<?php
function wp_signon( $credentials = '', $secure_cookie = '' ) {
if ( empty($credentials) ) {
if ( ! empty($_POST['log']) )
$credentials['user_login'] = $_POST['log'];
if ( ! empty($_POST['pwd']) )
$credentials['user_password'] = $_POST['pwd'];
if ( ! empty($_POST['rememberme']) )
$credentials['remember'] = $_POST['rememberme'];
}
@lesterchan
lesterchan / hhvm.conf
Created April 24, 2015 06:50
HHVM with PHP-FPM fallback
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 / delete_wordpress_revisions.php
Last active August 29, 2015 14:15
Delete WordPress Revisions
<?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 {