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 / cachedFetch.js
Created December 18, 2023 09:14 — forked from mritzco/cachedFetch.js
Javascript caching fetch data
// From https://www.sitepoint.com/cache-fetched-ajax-requests/
// All credits to: Peter Bengtsson
// Added Content-type to headers so it can go to traditional validation like fetch does
// Add some debugging messages: activate with { verbose: true }
// Add a request to be able to add headers instead of just calling URL
const CachedFetch = (url, options) => {
let expiry = options.seconds || 5 * 60 // 5 min default
let logger = (options.verbose) ? console.log : function(){};
@truongluu
truongluu / wc-sortable-custom-taxonomy.php
Created November 22, 2023 11:48 — forked from RadGH/wc-sortable-custom-taxonomy.php
Woocommerce - Sortable custom taxonomy
<?php
// This is so easy, it's embarassing that I took 20 minutes to find it.
// "Catalog" is a custom taxonomy.
function make_catalog_sortable( $sortables ) {
$sortables[] = 'catalog';
return $sortables;
}
add_filter( 'woocommerce_sortable_taxonomies', 'make_catalog_sortable' );
@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 / 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
'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.");
# Read more about setting it up
# https://medium.com/@ljmocic/deploying-react-application-to-aws-s3-using-github-actions-85addacaeace
on:
push:
tags:
- '*'
jobs:
build:
from django.db import connection, reset_queries
import time
import functools
def query_debugger(func):
@functools.wraps(func)
def inner_func(*args, **kwargs):
reset_queries()
@truongluu
truongluu / a-mongodb-replica-set-docker-compose-readme.md
Created April 26, 2021 03:50 — forked from harveyconnor/a-mongodb-replica-set-docker-compose-readme.md
MongoDB Replica Set / docker-compose / mongoose transaction with persistent volume

This will guide you through setting up a replica set in a docker environment using.

  • Docker Compose
  • MongoDB Replica Sets
  • Mongoose
  • Mongoose Transactions

Thanks to https://gist.github.com/asoorm for helping with their docker-compose file!

@truongluu
truongluu / ReactNative-Deep-Dive.md
Created December 16, 2020 02:30 — forked from nsimmons/ReactNative-Deep-Dive.md
ReactNative Deep Dive