Skip to content

Instantly share code, notes, and snippets.

@anthony9981
anthony9981 / list-and-find-large-file.sh
Created July 26, 2025 07:26
Using Terminal to Find Large Files and Folders
# change directory (drag and drop a folder from the Finder after it)
cd
# show current directory
pwd
# list files
ls
# list files with details
@anthony9981
anthony9981 / states.php
Created July 2, 2025 09:44
Cập nhật phường xã sau thay đổi hành chính - Việt Nam - 02/07/2025
<?php
$states['VN'] = array(
'THANH-PHO-HUE' => __( 'Thành phố Huế', 'woo-viet' ),
'THANH-PHO-HA-NOI' => __( 'Thành phố Hà Nội', 'woo-viet' ),
'TP-CAN-THO' => __( 'Tp Cần Thơ', 'woo-viet' ),
'TP-HAI-PHONG' => __( 'Tp Hải Phòng', 'woo-viet' ),
'TP-HO-CHI-MINH' => __( 'Tp Hồ Chí Minh', 'woo-viet' ),
'TP-DA-NANG' => __( 'Tp Đà Nẵng', 'woo-viet' ),
'TINH-AN-GIANG' => __( 'Tỉnh An Giang', 'woo-viet' ),
'TINH-BAC-NINH' => __( 'Tỉnh Bắc Ninh', 'woo-viet' ),
@anthony9981
anthony9981 / lazyrender.js
Created June 24, 2025 07:43
Elementor HTML Lazy Render Script
!function() {
var e = document.querySelectorAll("div[data-hiroman-lazy-render]");
if (e.length) {
var t = new IntersectionObserver(function(e, t) {
e.forEach(function(e) {
if (e.isIntersecting) {
var n = e.target.querySelector("noscript");
if (n) {
var r, o = (new DOMParser).parseFromString(n.textContent, "text/html");
(r = e.target).replaceWith.apply(r, o.body.childNodes);
@anthony9981
anthony9981 / elementor-html-lazy-render.php
Created June 24, 2025 07:42
Lazy HTML Render for Elementor
<?php
function add_lazy_render_to_elementor_sections($element, $section_id, $args)
{
if (in_array($element->get_name(), ['section', 'container'])) {
if (!$element->get_controls('hiroman_lazy_render')) {
$element->start_controls_section('flying_press', [
'tab' => \Elementor\Controls_Manager::TAB_ADVANCED,
'label' => esc_html__('Lazy Render HTML', 'hiroman'),
]);
@anthony9981
anthony9981 / bloat.php
Created June 24, 2025 07:40
Clear WordInstallation
<?php
/* Cleaner WP header
*===============================================================*/
function clean_header() {
// Remove the REST API lines from the HTML Header
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
@anthony9981
anthony9981 / convert-to-json.ts
Created September 24, 2024 16:58
Convert .ts languages to .json
import {glob} from 'glob';
import {writeFileSync} from 'fs';
import {basename, resolve} from 'path';
const languages = glob.globSync(resolve(process.cwd(), './languages/*.ts'));
languages.map((language:string) => {
const lang = require(language).default;
const langName = basename(language).split('.').shift();
writeFileSync(`./json/${langName}.json`, JSON.stringify(lang));
});
@anthony9981
anthony9981 / graceful_shudown.js
Created September 24, 2024 02:37
Graceful shutdown nodejs application
const terminator = (signal: string) => {
console.log(`Received ${signal}: ", "cleaning up`);
setTimeout(
(...args) => {
console.log(...args);
process.exit(0);
},
400,
"Message"
);
@anthony9981
anthony9981 / auto-click-try-again.js
Last active August 25, 2024 08:26
[Code Snipppet] Tự động click try again khi tiến trình bị gián đoạn cho plugin wp all import
setInterval(function() {
if (jQuery('#wpallimport-try-again').is(':visible')) {
jQuery('#wpallimport-try-again').click();
}
}, 5000);
@anthony9981
anthony9981 / elementor-phone-validation.php
Last active August 22, 2024 14:31
[Code Snippet] Thêm bộ lọc số điện thoại Việt Nam cho Elementor Pro
<?php
// Validate Tel in Elementor form
function elementor_form_validation( $record, $ajax_handler ) {
$fields = $record->get_field( [
'type' => 'tel',
] );
if ( empty( $fields ) ) {
return;
}
$field = current( $fields );
@anthony9981
anthony9981 / user.controller.ts
Created March 2, 2024 08:28 — forked from animir/user.controller.ts
Nest.js prevent brute-force against authorisation example
import { Request, Response } from 'express';
import { Body, Controller, Post, Req, Res } from '@nestjs/common';
import { UserService } from './user.service';
import * as Redis from 'ioredis';
import { RateLimiterRedis } from 'rate-limiter-flexible';
const redisClient = new Redis({enableOfflineQueue: false});
const maxWrongAttemptsByIPperDay = 100;
const maxConsecutiveFailsByUsernameAndIP = 5;