Skip to content

Instantly share code, notes, and snippets.

View nczz's full-sized avatar
🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。

一介資男 nczz

🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。
View GitHub Profile
@nczz
nczz / whatissoslow.php
Created October 29, 2023 14:23 — forked from Viper007Bond/whatissoslow.php
WordPress: Times how long it takes each filter and action to run and displays results at the end of the page. Quick and dirty.
<?php
/**
* This little class records how long it takes each WordPress action or filter
* to execute which gives a good indicator of what hooks are being slow.
* You can then debug those hooks to see what hooked functions are causing problems.
*
* This class does NOT time the core WordPress code that is being run between hooks.
* You could use similar code to this that doesn't have an end processor to do that.
*
/**
* HOW-TO
*/
// same param as $.ajax(option); see http://api.jquery.com/jQuery.ajax/
$.ajaxQueue.addRequest(option);
// start processing one by one requests
$.ajaxQueue.run();
@nczz
nczz / LightSail WordPress Cluster
Created May 2, 2022 02:24 — forked from mukeshwani/LightSail WordPress Cluster
Command, Code Snippts and Instructions for following video tutorial on setting up LightSail WordPress Cluster
# Welcome to the lightsail-wordpress-cluster wiki!
## Instructions, commands and code snippets to use and follow along the Video Tutorial on YouTube.
## Create Four LightSail Ubuntu Servers with the appropriate sizing. Name Three instances WP1, WP2, WP3, and name 4th instance LoadBalancer
##
## Open Ports 443 and 9443 (on LoadBalancer and WP1 in the LightSail Instance networking section)
## Run all commands with root (sudo su)
### Run following on each of the 3 WordPress instances
`ufw allow 80,443,9443,3306,4444,4567,4568/tcp;`
// import_json_appsscript.js
// https://gist.github.com/allenyllee/c764c86ed722417948fc256b7a5077c4
//
// Changelog:
// (Oct. 16 2019) tag: allenyllee-20191016
// 1. Fixed google script error: urlfetchapp - service invoked too many times https://stackoverflow.com/questions/10598179/google-apps-script-urlfetchapp-service-invoked-too-many-times
// (Jul. 16 2018) tag: allenyllee-20180716
// 1. Fixed the issue "If you try to query /arrayA[k]/arrayB[n]/arrayC[m]/.../member, you will always get /arrayA[k]/arrayB[k]/arrayC[k]/.../member."
// (Nov. 30 2017) tag: allenyllee-20171130
// 1. Add the ability to query array elements by using xpath like "/array[n]/member" where "n" is array index
@nczz
nczz / get_instagram_media.php
Last active September 10, 2020 15:59 — forked from gsarig/get_instagram_media.php
[WordPress] 使用 Instagram API 嵌入圖文至網站的正確做法(2020/07後適用) https://www.mxp.tw/9037/
<?php
/**
* 使用 Instagram (Facebook) API 取得用戶圖文的方法,翻譯自原文: https://www.gsarigiannidis.gr/instagram-feed-api-after-june-2020/
*
* @param $token // 存取權杖
* @param $user // 用戶編號,查詢工具: https://developers.facebook.com/tools/debug/accesstoken/
* @param int $limit // 查詢圖文筆數(不建議設定太多).
* @param string $fields // 其他欄位參考: https://developers.facebook.com/docs/instagram-basic-display-api/reference/media
* @param array $restrict // 取得媒體類型: IMAGE, VIDEO, CAROUSEL_ALBUM
*
@nczz
nczz / gist:dad560c10c3b36ffba763e399129ce6f
Last active November 28, 2019 13:29 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page 維護頁面範本
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
@nczz
nczz / psql-error-fix.md
Created March 3, 2019 05:24 — forked from AtulKsol/psql-error-fix.md
Solution of psql: FATAL: Peer authentication failed for user “postgres” (or any user)

psql: FATAL: Peer authentication failed for user “postgres” (or any user)

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql. So you will have to create the UNIX user postgres and then login as postgres or use sudo -u postgres psql database-name for accessing the database (and psql should not ask for a password).

If you cannot or do not want to create the UNIX user, like if you just want to connect to your database for ad hoc queries, forcing a socket connection using psql --host=localhost --dbname=database-name --username=postgres (as pointed out by @meyerson answer) will solve your immediate problem.

But if you intend to force password authentication over Unix sockets instead of the peer method, try changing the following pg_hba.conf* line:

from

@nczz
nczz / install-postgres-10-ubuntu.md
Last active February 25, 2019 10:28 — forked from alistairewj/install-postgres-10-ubuntu.md
Install PostgreSQL 10 on Ubuntu

Install PostgreSQL 10 on Ubuntu

This is a quick guide to install PostgreSQL 10 - tested on Ubuntu 16.04 but likely can be used for Ubuntu 14.04 and 17.04 as well, with one minor modification detailed below.

(Optional) Uninstall other versions of postgres

To make life simple, remove all other versions of Postgres. Obviously not required, but again, makes life simple.

dpkg -l | grep postgres
@nczz
nczz / get-order-detail-by-order-id-2_6.php
Created September 8, 2018 17:24 — forked from web-hat/get-order-detail-by-order-id-2_6.php
Works with WooCommerce 2.6.x or below
<?php
if (!function_exists('getOrderDetailById')) {
function getOrderDetailById($id, $fields = null, $filter = array()) {
if (is_wp_error($id))
return $id;
// Get the decimal precession
@nczz
nczz / get-order-detail-by-order-id.php
Last active September 8, 2018 17:28 — forked from web-hat/get-order-detail-by-order-id.php
Works with WooCommerce 3.x or above
<?php
if (!function_exists('getOrderDetailById')) {
//to get full order details
function getOrderDetailById($id, $fields = null, $filter = array()) {
if (is_wp_error($id)){
return false;
}