Skip to content

Instantly share code, notes, and snippets.

@simongcc
simongcc / WordPress-Force-Post-ID.php
Created Apr 7, 2020
Force to change current page post object in WordPrress
View WordPress-Force-Post-ID.php
<?php
// $post = get_post( 33, OBJECT ); // use ID or
$post = get_page_by_path( $path ); // url path such as /people/staff or /people/staff/ both work
setup_postdata( $post ); // change global post object
$post->ID; // new ID
wp_reset_postdata(); // reset to original post data
?>
View YouTube API — getting video thumbnail
Each YouTube video has 4 generated images. They are predictably formatted as follows:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
@simongcc
simongcc / custom-search-acf-wordpress.php
Created Mar 2, 2020 — forked from charleslouis/custom-search-acf-wordpress.php
PHP - Wordpress - Search - wordpress custom search function that encompasses ACF/advanced custom fields and taxonomies and split expression before request
View custom-search-acf-wordpress.php
<?php
/**
* [list_searcheable_acf list all the custom fields we want to include in our search query]
* @return [array] [list of custom fields]
*/
function list_searcheable_acf(){
$list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
return $list_searcheable_acf;
}
@simongcc
simongcc / wp-sample-add_post_type_support.php
Created Jan 21, 2020
Wordpress - add post type support to existing post types
View wp-sample-add_post_type_support.php
function sing_update_post_types_support() {
// add_post_type_support( 'events', 'post-formats' );
}
add_action( 'init', 'sing_update_post_types_support' );
@simongcc
simongcc / horizontal-infinite-carousel.html
Created Oct 30, 2019 — forked from dongyuwei/horizontal-infinite-carousel.html
infinite loop carousel(vertical or horizontal)
View horizontal-infinite-carousel.html
View 日中歌對照
http://www.youtube.com/watch?v=Z3djBbe4Yw8 俺たちの旅/中村雅俊 (羅文 前程錦繡 原曲)
http://www.youtube.com/watch?v=9FqQOMkIAMs それが大事/大事MANブラザーズバンド (李克勤 紅日 原曲)
http://www.youtube.com/watch?v=kZdFC5s-eLY 愛は勝つ/KAN (張學友 壯志驕陽 原曲)
http://www.youtube.com/watch?v=nFrtSOYLwKU 悲しい気持ち/桑田佳祐 (古巨基 藍天與白雲 原曲)
http://www.youtube.com/watch?v=IFKyQxksGIo 負けないで/ZARD (坂井泉水係才女,但係好慘,死果時只有四十)
http://www.youtube.com/watch?v=EtX1fmIA9Go My revolution/渡辺美里 (電影反轉豬腩是王子主曲)
http://www.youtube.com/watch?v=krNlM7yVL68 Tsunami/Southern All Stars (感人情歌)
http://www.youtube.com/watch?v=CkmnW_V5OeUどんなときも/槇原敬之 (槇原敬之成名作)
http://www.youtube.com/watch?v=AmaAMnEyRYI 遥かなる夢に/Beyond (海闊天空日文版)
View gist:d10f3f9d3534ab479035a5e13798cc81
# Mac OS 10.12.16
Step
1. Open Disk Util
2. New Image > Blank Image
3. Settings:
Image Format: DVD/CD Master
Partition map: (No Partition map), if set, it will fail
Format: ExFat / MacOS both working
Size: Size needed
@simongcc
simongcc / exportExif.sh
Created May 9, 2019
Export Exif files from jpeg using shell script
View exportExif.sh
# #!/bin/sh is called shebang
# ref: https://en.wikipedia.org/wiki/Shebang_(Unix)
# #!/usr/bin/env bash means looking into the path and call the first bash found in the path
# ref: https://unix.stackexchange.com/questions/29608/why-is-it-better-to-use-usr-bin-env-name-instead-of-path-to-name-as-my
# bash script if or
# ref: https://stackoverflow.com/questions/3826425/how-to-represent-multiple-conditions-in-a-shell-if-statement
# check file extension
@simongcc
simongcc / auto-put-back.scpt
Created May 2, 2019
Apple script for auto put back files
View auto-put-back.scpt
# original: https://discussions.apple.com/thread/7831626
# keyboard keycodes: https://eastmanreference.com/complete-list-of-applescript-key-codes
tell application "System Events"
tell process "Finder"
repeat 100 times
tell application "Finder" to open trash
tell application "Finder" to activate
key code 126
key down command
key code 51
@simongcc
simongcc / _archive-project.bat
Created Apr 26, 2019
Windows batch zip project files with date stamp (legacy backup method by Schedule)
View _archive-project.bat
@echo off
rem get local date time
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
rem set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
set ldt=%ldt:~0,4%%ldt:~4,2%%ldt:~6,2%-%ldt:~8,2%%ldt:~10,2%%ldt:~12,2%
set destination=U:\Project-by-Set-Grp
set destination2=Z:\_Project_Bak
set zip_exe="C:\Program Files\7-Zip"
set config_file="C:\Users\XXXXX\Dropbox\_work\_backup_data"
set dropbox_bak="U:\Project-by-Set-Grp"