Skip to content

Instantly share code, notes, and snippets.

View alucard001's full-sized avatar

Ellery Leung alucard001

View GitHub Profile
@alucard001
alucard001 / csv_for_excel.php
Created January 18, 2017 03:32
PHP CSV for Excel file download
<?php
// Prepare file download
// Special Thanks: https://www.skoumal.net/en/making-utf-8-csv-excel/
$filename = 'some_file_name.csv';
//headers
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
@alucard001
alucard001 / clean_email.py
Last active January 18, 2017 03:54
Python Validate Email example script
# coding: utf-8
import pandas as pd
import numpy as np
from validate_email import validate_email
import sys
# Note: you may encounter error if you don't have pyDNS or pyDNS3 installed.
import DNS
DNS.defaults["server"] = ["8.8.8.8", "8.8.4.4"]
@alucard001
alucard001 / numerai.py
Last active January 17, 2018 01:15
Using TPOT Classifier to analysis Numerai dataset
"""
Largely come from TPOT example. The only control you can do to prevent timeout
and successful running is the "generation" and "population_size" parameters.
Remember, scoring is "log_loss" as of 18 Jan 2017, not probability
The larger the generation and population_size, the longer time you take to get result.
"""
from tpot import TPOTClassifier
from sklearn.model_selection import train_test_split
@alucard001
alucard001 / woocommerce-product-category.php
Created April 30, 2017 09:44
WooCommerce Product Category List
<?php
/**
* @package Woocommerce Product Category List
* @version 1.0
*/
/*
Plugin Name: Woocommerce Product Category List table
Plugin URI: https://www.linkedin.com/in/elleryleung
Description: This plugin is just add a new shortcode: <code>[bp_product_category]</code> to list all product categories in div format.
Author: Ellery Leung
@alucard001
alucard001 / check_email_server_alive.py
Last active May 17, 2017 10:06
Python 2 Linux send email through Gmail using SMTP
# Python 2 Script. It works as of 17 May 2017
import os
if "CONNECTED" not in os.popen("/usr/bin/openssl s_client -connect 192.168.1.15:25 | /bin/grep '^CONNECTED'").read():
# Note about sending email using Gmail SMTP
# https://www.digitalocean.com/community/tutorials/how-to-use-google-s-smtp-server
# http://stackoverflow.com/questions/20337040/gmail-smtp-debug-error-please-log-in-via-your-web-browser
# How to send email using Linux Command: http://www.binarytides.com/linux-mailx-command/
@alucard001
alucard001 / apns.py
Created June 2, 2017 04:13
Python Apple Push Notification HTTP/2 Example - Silent Push
"""
Use HTTP/2 send APNS Example main reference
===========================================
http://gobiko.com/blog/token-based-authentication-http2-example-apns/
Error 410 to detect uninstalls
==============================
https://leftshift.io/mobile-tracking-uninstalls-on-ios-and-android
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW1
@alucard001
alucard001 / googlesearch.py
Last active June 24, 2019 04:09
Google Search API Working Example - Python 3 + MSSQL
#!/usr/local/bin/python3
'''
This program is used to get all search terms in Google search console and save it in MSSQL DB.
Please note: Just using this .py is not enough. You need to create a Google service account in google API console and
connect that service account to Google search console property.
Points to note:
===============
@alucard001
alucard001 / GoogleIndexing.py
Created May 27, 2019 04:49
Google Indexing API V3 Working example with Python 3
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
import json
import pandas as pd
# https://developers.google.com/search/apis/indexing-api/v3/prereqs#header_2
JSON_KEY_FILE = "json_key_file_downloaded_after_creating_your_google_service_account_see_above_details_on_how_to_do.json"
SCOPES = ["https://www.googleapis.com/auth/indexing"]
@alucard001
alucard001 / GetNextBusinessDay.php
Created March 30, 2020 02:57
[PHP]Get Next Business Day, include/not include holiday
<?php
/**
* One of my task is to create a function that find the next business day.
*
* Reference: https://stackoverflow.com/a/5532070/1802483
*/
class GetNextBusinessDay{
// Get a list of holiday in https://holidayapi.com/. Then I copy, paste and edit it manually to make this list
private $holidayList = [
"2020-04-04",