Skip to content

Instantly share code, notes, and snippets.

View woraperth's full-sized avatar
🏠
Working from home

Perth Ngarmtrakulchol woraperth

🏠
Working from home
View GitHub Profile
# ---- DB Search-Replace and Backup Script ----
# Note: This requires WP-CLI to be installed http://wp-cli.org/
#
# This will generate new SQL file for import to new URL
# 1. Old DB - for Backup purpose (old URL): backup-yymm.sql
# 2. Replaced DB - ready for deploy (new URL): replaced-yymm.sql
#
# Replace aaa.com to bbb.com in the script below
#
# Note: Sometimes you need to change permission with
<?php
/* Original Script from: http://stackoverflow.com/questions/1294117/how-to-change-collation-of-database-table-column */
/* Note: This script will loop through all the tables and change collation to utf8_general_ci
But it will not change database's collation. The only way to change database collation might be to delete and create it again.
/*
$con = mysql_connect('localhost','db_user','db_pass'); /* Edit DB Username / Password */
if(!$con) { echo "Cannot connect to the database ";die();}
mysql_select_db('db_name'); /* Edit DB Name */
$result=mysql_query('show tables');
while($tables = mysql_fetch_array($result)) {
@woraperth
woraperth / Movefile
Created November 18, 2015 14:47
Working Movefile for Wordmove with SSH (MAMP to DigitalOcean)
local:
vhost: "http://localhost/xxx"
wordpress_path: "/Applications/MAMP/htdocs/xxx" # use an absolute path here
database:
name: "xxx"
user: "root"
password: "root"
host: "localhost"
@woraperth
woraperth / foundaton-es5.js
Created March 9, 2016 09:45
Foundation 6 ES5 version for Essential Download (Fixing "class is a reserved identifier" problem)
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
!(function ($) {
'use strict';
@woraperth
woraperth / wp-config.php
Last active April 29, 2017 14:31
WordPress Config for Ngrok
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
// Run ngrok by:
// ./ngrok http -host-header=dev.test.com 80
@woraperth
woraperth / wp-get-youtube-thumb.php
Last active August 15, 2024 23:23
[WordPress] Get Youtube video thumbnail from URL & Set as Featured Image
// Get Youtube URL
$yturl = 'https://www.youtube.com/watch?v=HhAKNSsb4t4';
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $yturl, $matches);
$video_id = $matches[1];
// Get Thumbnail
$file_headers = get_headers( 'http://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg' );
$is_404 = $file_headers[0] == 'HTTP/1.0 404 Not Found' || false !== strpos( $file_headers[0], '404 Not Found' );
$video_thumbnail_url = $is_404 ? 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' : 'http://img.youtube.com/vi/' . $video_id . '/hqdefault.jpg';
@woraperth
woraperth / inlineimg.php
Created April 24, 2017 15:39
Add Inline Image in FPDF
class PDF extends FPDF
{
// Inline Image
function InlineImage($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='')
{
// ----- Code from FPDF->Image() -----
// Put an image on the page
if($file=='')
$this->Error('Image file name is empty');
if(!isset($this->images[$file]))
@woraperth
woraperth / webSocket.js
Last active April 6, 2024 20:56
JavaScript Singleton to connect to WebSocket (originally for React project)
// Thank you Ranatchai Chernbamrung for sample socketIO singleton pattern
// This code is originally for my React project, but should work with any ES6 project that support `import` statement
// How it works
// 1. Create webSocket.js to establish the connection and retrieve the connection
// 2. In main file, import webSocket.js to establish the connection
// 3. In other component files, import webSocket.js to retrieve the connection
// webSocket.js
let client
@woraperth
woraperth / fb.js
Created November 2, 2017 07:01
Bulk invite in Facebook page
// Run this in console when the invite list page is opened e.g. click the number of likes on each post
// Caution: use at your own risk! Facebook may temporarily ban your action if you invite too many (100+) at a time.
var x = document.querySelectorAll('._42ft._4jy0._4jy3._517h._51sy:not(._5f0v)')
for(var i=0; i<x.length; i++){
x[i].click();
}
@woraperth
woraperth / template-functions.php (for taxonomy)
Last active August 15, 2024 23:24
[WordPress] Add ACF Admin Column to taxonomy (In this example, taxonomy name = product_category & ACF column name = english_name)
// Add ACF Columns
function add_new_product_cat_column($column) {
$column['english_name'] = 'English Name';
return $column;
}
add_filter('manage_edit-product_category_columns', 'add_new_product_cat_column');
function add_new_product_cat_admin_column_show_value( $content, $column_name, $term_id ) {