Skip to content

Instantly share code, notes, and snippets.

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

Vitor Carvalho lightningspirit

🏠
Working from home
View GitHub Profile
@lightningspirit
lightningspirit / README.md
Last active April 21, 2024 08:47
Intercepts WordPress posts and terms changes and pings an external service

WordPress Ping Updates

This plugin intercepts WordPress posts and terms changes and pings an external service.

Usage

  1. Download this ZIP
  2. Add define('PING_UPDATES_URL', 'https://my-service.com/api'); to wp-config.php or ping_updates_url option in wp_options
  3. Optionally, add define('ENABLE_PING_UPDATES_ON_TERMS_POSTS', true); if you want to ping each associated post when a term is changed
  4. Add an option ping_updates_authz_token in wp_options where the value is the token to include in the Authorization header
  5. Upload to plugins of your WordPress
@lightningspirit
lightningspirit / README.md
Created April 10, 2024 17:32
React Immutable Data Structures Hooks

React Immutable Data Structures Hooks

Popular data structures implemented in immutable React hooks.

Hooks:

  • useArray
  • useHeap
  • useList
  • useQueue
  • useStack
@lightningspirit
lightningspirit / README.md
Last active March 25, 2024 16:24
Docker Client Plugin to SSH Remote Docker Hosts

Docker Client Plugin to SSH Remote Docker Hosts

Configuration for each project using a simple YAML file. The docker remote command reads the relative local file docker-remote.yml to access docker hosts. Uses SSH under the hood.

Examples of usage

Showing remote running containers

Implicit user parameter

docker remote remote-hostname ps

function useFileUpload() {
const [total, setTotal] = useState(0)
const [file, setFile] = useState<File>()
const [paused, setPaused] = useState(false)
const [uploaded, setUploaded] = useState(0)
const pause = () => setPaused(true)
const resume = () => setPaused(false)
function upload(file: File) {
@lightningspirit
lightningspirit / create-i18n-context.ts
Last active February 6, 2024 17:07
React I18n only server side
import 'server-only'
import serverOnlyContext from './server-only-context'
export type Locale = string
export const I18nContext = serverOnlyContext<Locale>('en')
@lightningspirit
lightningspirit / vscode-sr-snippets.md
Created December 18, 2023 19:32
Visual Studio Code - Search - Replace snippets

VSCode Search & Replace Snippets

A collection of snippets to perform tasks to convert code syntax in some languages.

TypeScript

Convert NextJS dynamic import into full import

Example

const EmailIcon = dynamic(() =&gt; import("images/icons/buttons/email-button.svg"))
@lightningspirit
lightningspirit / README.md
Last active December 12, 2023 03:03
WordPress Multisite Network Plugin management

WordPress Multisite Network Plugin management

For multisite network ONLY Adds a new Plugins tab under wp-admin/network/sites.php which gives the ability to enable or disable (without actually activate) plugins per site.

This just "hides" not enabled plugins from the site plugins area.

Note: the super-admin can still have access to all plugins, even for each specific website which is great because the super-admin can activate hidden plugins :-)

@lightningspirit
lightningspirit / object-cache.php
Created December 9, 2023 15:18
WordPress APCu Object Cache
<?php
/*
Plugin Name: WordPress APCu Object Cache Backend
Plugin URI: https://github.com/l3rady/WordPress-APCu-Object-Cache
Description: APCu backend for WordPress' Object Cache
Version: 1.1
Author: Scott Cariss
Author URI: http://scott.cariss.dev
*/
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 61
model name : Intel Core Processor (Broadwell, no TSX, IBRS)
stepping : 2
microcode : 0x1
cpu MHz : 2394.454
cache size : 16384 KB
@lightningspirit
lightningspirit / parseHttpHeader.test.ts
Created October 26, 2023 23:37
Parses HTTP header based on format of RFC-9110
import parseHttpHeader from "./parseHttpHeader"
describe("functions/parseHttpHeader", function () {
it.each([
[
"users=0-10/100",
{
users: "0-10/100",
},
],