Skip to content

Instantly share code, notes, and snippets.

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

Lưu Xuân Trường truongluu

🏠
Working from home
View GitHub Profile
@truongluu
truongluu / create_order.php
Created November 11, 2023 08:54 — forked from shitpoet/create_order.php
Programmatically create order, add (variative) products from cart to it, change status to `processing` and empty cart. Wordpress, WooCommerce 2.4.
$address = array(
'first_name' => $customer_name,
'last_name' => '',
'company' => '',
'email' => $customer_email,
'phone' => $customer_phone,
'address_1' => '',
'address_2' => '',
'city' => '',
'state' => '',
@truongluu
truongluu / SubmitFormHandler.tsx
Last active April 15, 2023 12:18
How to type a React Form with submit handler
import React from 'react';
export type GenHTMLFormControlsCollection<T> = HTMLFormControlsCollection & {
[inputName in keyof T]: HTMLInputElement;
};
interface GenericFormElement<T extends { [inputName: string]: HTMLInputElement }>
extends HTMLFormElement {
readonly elements: GenHTMLFormControlsCollection<T>;
}
@truongluu
truongluu / package.json
Created December 9, 2022 08:46
Gulp WP Theme - Package
{
"name": "wpsitename",
"version": "1.0.0",
"description": "",
"author": "jacekolczak",
"private": true,
"devDependencies": {
"gulp": "latest",
"gulp-livereload": "latest",
"gulp-sass": "latest",
@truongluu
truongluu / gulpfile.js
Created December 9, 2022 08:45
Gulp configs for WP
var gulp = require('gulp'),
sass = require('gulp-sass')(require('sass')),
livereload = require('gulp-livereload'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
dest = require('gulp-dest'),
order = require('gulp-order'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('gulp-autoprefixer')
rename = require('gulp-rename'),
@truongluu
truongluu / compose-function.js
Created May 16, 2022 04:54
Compose function
/**
* Composes single-argument functions from right to left. The rightmost
* function can take multiple arguments as it provides the signature for
* the resulting composite function.
*
* @param {...Function} funcs The functions to compose.
* @returns {Function} A function obtained by composing the argument functions
* from right to left. For example, compose(f, g, h) is identical to doing
* (...args) => f(g(h(...args))).
*/
@truongluu
truongluu / curry-function.js
Created May 15, 2022 08:33
Curry function
/***
* function sum(a,b,c) { return a +b + c;}
* const cSum = curry(sum)
* cSum(1, 2, 3) => 6
* cSum(1)(2)(3) => 6
* cSum(1)(2,3) => 6
*/
function curry(func) {
return (...args) => {
@truongluu
truongluu / EventTarget.addEventListener.js
Created May 11, 2022 04:08 — forked from fuzzyfox/EventTarget.addEventListener.js
JavaScript: EventTarget.addEventListener shim
// target.addEventListener shim, hat tip [mdn](http://mzl.la/18ELrGJ)
(function() {
if (!Event.prototype.preventDefault) {
Event.prototype.preventDefault=function() {
this.returnValue=false;
};
}
if (!Event.prototype.stopPropagation) {
Event.prototype.stopPropagation=function() {
this.cancelBubble=true;
@truongluu
truongluu / .git-commit-template.txt
Created April 10, 2022 02:57 — forked from adeekshith/.git-commit-template.txt
This commit message template helps you write great commit messages and enforce it across teams.
# <type>: (If applied, this commit will...) <subject> (Max 50 char)
# |<---- Using a Maximum Of 50 Characters ---->|
# Explain why this change is being made
# |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->|
# Provide links or keys to any relevant tickets, articles or other resources
# Example: Github issue #23
@truongluu
truongluu / replSet-mongodb-centos7.txt
Created April 2, 2022 02:36
Relicate Set mongodb on centos 7
I. Mongo 1
IP: 192.168.111.142
yum install epel-release -y
yum update -y
vi /etc/hosts
192.168.111.142 mongo01
192.168.111.143 mongo02
192.168.111.144 mongo03
setenfore 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
'use strict';
class Abstract {
// A static abstract method.
static foo() {
if (this === Abstract) {
// Error Type 2. Abstract methods can not be called directly.
throw new TypeError("Can not call static abstract method foo.");
} else if (this.foo === Abstract.foo) {
// Error Type 3. The child has not implemented this method.
throw new TypeError("Please implement static abstract method foo.");