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
$ 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",
},
],
@lightningspirit
lightningspirit / wp-disable-plugin-update-notifications.php
Last active September 12, 2023 16:34
Disable WordPress plugin updates and notifications
<?php
namespace WP_Disable_Plugin_Update_Notifications;
$plugins = [
'elementor/elementor.php',
'elementor-pro/elementor-pro.php',
];
add_filter( 'site_transient_update_plugins', function ( $value ) use ( $plugins ) {
@lightningspirit
lightningspirit / custom-plugin.php
Last active May 24, 2023 10:48
WordPress Custom Plugin - Can be used to add any code using the online editor
<?php
/**
* Plugin Name: Custom
* Plugin URI: https://gist.github.com/lightningspirit/4619cb99fcb662b390d9596df1479d41
* Description: Custom code for everybody
* Author: Move Your Digital
* Author URI: https://moveyourdigital.com
* Version: 1.0.0
*
@lightningspirit
lightningspirit / buildQueryString.ts
Created October 29, 2022 09:31
A function that takes an object and outputs a query string. Booleans are mapped into 1 and 0. Supports arrays of values.
type ValueType =
| string
| number
| boolean
| null
| undefined
| (string | number | boolean | null | undefined)[]
function mapBooleans(key: string, value: ValueType) {
switch (value) {
@lightningspirit
lightningspirit / README.md
Created September 20, 2022 00:37
Add excerpt to page

WordPress Page Excerpt

Add excerpt field to page

Usage

  1. Download this ZIP
  2. Upload to plugins
  3. Activate it
@lightningspirit
lightningspirit / README.md
Last active November 26, 2024 12:51
Includes a `readingTime` field in seconds for every `Post` object response.

WPGraphQL Post Reading Time

Includes a readingTime field in seconds for every Post object response.

Usage

  1. Download this ZIP
  2. Upload to plugins
  3. Activate it
@lightningspirit
lightningspirit / useFSM.tsx
Created September 6, 2022 13:39
Preact Hook Finite State Machine
import { useCallback, useEffect, useMemo, useState } from "preact/hooks"
class StateTransitionError extends Error {}
function useFSM<T extends string>(
transitions: Record<T, T[]>,
options: {
throwOnTransitionError?: boolean
} = { throwOnTransitionError: true },
) {
@lightningspirit
lightningspirit / README.md
Created August 22, 2022 00:30
Includes a WPGraphQL JWT token in every posts preview link

WPGraphQL JWT in Preview Link

Includes a WPGraphQL JWT token in every posts preview link. That can be used for an external application (e.g. Next.js) to include in the authorization header when contacting back the WordPress instance using the WPGraphQL.

Usage

  1. Install both WPGraphQL and WPGraphQL JWT Authentication
  2. Download this ZIP
  3. Upload to plugins
  4. Activate it
@lightningspirit
lightningspirit / ping-updates.php
Last active August 8, 2024 15:26
Intercepts WordPress posts and terms changes and pings an external service
<?php
/**
* Plugin Name: Ping Updates
* Plugin URI: https://gist.github.com/lightningspirit/7a4e5abd77b5b63b3409086f1ac6aa55
* Description: Intercepts posts and terms changes and pings an external service
* Author: Move Your Digital, Inc.
* Author URI: https://moveyourdigital.com
* Version: 0.2.0
* License: GPLv2