Skip to content

Instantly share code, notes, and snippets.

View spicydog's full-sized avatar

spicydog spicydog

View GitHub Profile
package main
import "encoding/json"
// Unescape UTF-8 string
// e.g. convert "\u0e27\u0e23\u0e0d\u0e32" to "วรญา"
func UnescapeString(str string) (unescapedString string) {
json.Unmarshal([]byte(`"`+str+`"`), &unescapedString)
return
}
@spicydog
spicydog / .gitlab-ci.sh
Created August 29, 2020 16:41
SPICYDOG's Podcast EP 4 : Sample Scripts
#!/bin/sh
# exit with error
set -e
# Generate an application key. Re-cache.
php artisan config:cache
php artisan config:clear
php artisan cache:clear
@spicydog
spicydog / main.py
Created October 24, 2020 16:00
A Google Cloud Function to copy/clone a file from one Google Cloud Storage bucket to another with the same file path.
import os
from google.cloud import storage
OUTPUT_BUCKET = os.environ['OUTPUT_BUCKET']
def clone_gcs_file(event, context):
print(f"rev.4")
INPUT_BUCKET = event['bucket']
@spicydog
spicydog / No-IP Update with PHP and Crontab
Last active February 17, 2020 12:34
PHP Script for updating ip for no-ip DDNS and example script for crontab
# Update no-ip ip every one hour
0 * * * * curl "YOUR_HOST_URL/noip-updater.php" > /dev/null 2>&1
@spicydog
spicydog / generate.js
Created February 8, 2020 15:49
Central Limit Theorem
const times = 20;
const n = 5
const set = {
1: 1,
2: 5,
3: 7,
4: 5,
5: 1,
@spicydog
spicydog / dockerfile
Created September 24, 2016 14:58
docker ubuntu nginx php7.0 mariadb
FROM ubuntu:latest
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y vim curl wget
RUN apt-get install -y software-properties-common language-pack-en-base
RUN LC_ALL=en_US.UTF-8 add-apt-repository -y ppa:ondrej/php
RUN apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
RUN add-apt-repository -y 'deb [arch=amd64,i386,ppc64el] http://mirrors.bestthaihost.com/mariadb/repo/10.1/ubuntu xenial main'
@spicydog
spicydog / thai_national_id_validation.php
Last active July 13, 2018 08:11
The PHP function to check Thai national ID
/**
* Validate Thai national ID
* @param string $nationalId
* @link https://th.wikipedia.org/wiki/เลขประจำตัวประชาชนไทย
* @return bool
*/
public function isValidNationalId(string $nationalId)
{
if (strlen($nationalId) === 13) {
$digits = str_split($nationalId);

On Caldera Forms, when you export entries as CSV.

It cannot be open perfectly with excel because it missing BOM in file prefix.

Therefore, we have to intercept the process and here is how to.

At the file wp-content/plugins/caldera-forms/classes/admin.php.

There is a function to export the CSV here.

@spicydog
spicydog / editor-style.css
Created April 1, 2018 05:26
spicydog.org Wordpress's Editor CSS
/*
Theme Name: Twenty Eleven
Description: Used to style the TinyMCE editor.
*/
@import url("https://cdn.spicydog.org/fonts/th-sarabun-new/th-sarabun-new.css");
@import url("https://cdn.spicydog.org/fonts/thaisans-neue/thaisans-neue.css");
body {
color: #333;
หากวาง = หา|กวาง / หาก|วาง
ปีกว่า = ปี|กว่า / ปีก|ว่า
เกษตรกรอบกรอบ = เกษตรกร|อบ|กรอบ / เกษตร|กรอบ|กรอบ