Skip to content

Instantly share code, notes, and snippets.

View davidwebca's full-sized avatar

David Lapointe Gilbert davidwebca

View GitHub Profile
@davidwebca
davidwebca / cache-warmer.js
Created June 13, 2024 14:38
Simple ajax cache warmer based on sitemap.xml
/**
* This cache warmer uses everything located in the sitemap.xml
* of the current opened website. Just copy and paste all of this
* in the browser console while the target website is opened.
*/​
async function crawl() {
let urls = [];
async function getUrls() {
await fetch(`${window.location.origin}/sitemap.xml`).then(response => response.text())
.then(str => new window.DOMParser().parseFromString(str.trimStart(), "text/xml"))
@davidwebca
davidwebca / USAGE
Last active June 5, 2024 19:45 — forked from bantya/USAGE
Convert sublime snippets to vscode.
php snippets.php [SNIPPETS_DIRECTORY]
e.g. php snippets.php vue
SNIPPETS_DIRECTORY: Assuming that the snippets are categorized in directories (preferably by languages) and snippet directories and the script have the same parent directory.
e.g.
/snippets
|
+--- snippets.php
|
+--- /php
@davidwebca
davidwebca / AutoGraphql.js
Created December 4, 2023 15:11
Get GraphQL data automatically based on Nuxt/Vue component's name
import { getCurrentInstance } from 'vue';
export async function useAutoGraphql(vars = {}, options = {}) {
let cwd = null;
if (process.server) {
cwd = useState('___cwd', () => process.cwd());
} else {
cwd = useState('___cwd');
}
const inst = getCurrentInstance();
@davidwebca
davidwebca / install-curl.sh
Last active November 30, 2023 19:58
Install and compile Curl with SFTP support on Mac
sudo rm /usr/local/bin/curl
sudo rm /usr/local/bin/curl-config
# If needed
# xcode-select --install
brew install git brotli git-ftp openssl libssh2
brew uninstall --ignore-dependencies curl
curl https://curl.se/download/curl-8.4.0.zip --output curl.zip
unzip curl.zip
@davidwebca
davidwebca / JsondTwigExtension.php
Last active March 17, 2023 13:28
JsondTwigExtension to fix some weird json_encode issues
<?php
/**
* Based on Indigo Viking's Twig Extension
* @see https://github.com/IndigoViking/Jsond/
*/
namespace modules\twigextensions;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
@davidwebca
davidwebca / mamp-php-apache.md
Last active November 18, 2022 17:15
Use MAMP's Apache selected PHP version on CLI

How to set your command line to MAMP's version

Since Mac OS comes with PHP bundled, even if you have MAMP, you'll find out that you can't use MAMP's versions on the command line. This is only true if you use the free version of MAMP since MAMP pro seems to have a feature to add that to the cli automatically.

Open your ~/.bash_profile file or ~/.zshrc if using ZSH

In this file, you might see nothing or only a few configurations already. You can safely ignore them and add this lower:

PHP_VERSION=$(grep "^[^#\;]" "/Applications/MAMP/conf/apache/httpd.conf" | grep "LoadModule php" | awk -F'[\/]' '{print $6}')
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
export PATH=/Applications/MAMP/Library/bin:$PATH
@davidwebca
davidwebca / fix-woo-learndash-sub-rollback.php
Created September 26, 2022 21:24
Fix learndash_woocommerce.php + WooCommerce Subscription rollback issue
<?php
/**
* Theme filters.
*/
namespace App;
/**
* Fix checkout bug with learndash_woocommerce
*
* learndash_woocommerce.php:580
@davidwebca
davidwebca / lazyblock-tailwind-cache.php
Last active June 24, 2022 00:09
Create tmp files for Lazy Block to allow Tailwind CSS to watch for CSS class names and create / purge properly
<?php
/**
* Allows HTML + Handlebars or database-saved PHP code to be
* cached into files so that Tailwind CSS can detect and watch
* for classes used and purge unecessary ones.
*
* @see https://github.com/nk-crew/lazy-blocks/
* @see https://github.com/nk-crew/lazy-blocks/issues/246
*/
@davidwebca
davidwebca / post-ftp-push
Last active December 11, 2023 16:01
git-ftp rsync hook
#!/bin/bash
remote="$1"
originalurl="$2"
# I created this bash script to hook with git-ftp since the .git-ftp-include mecanism
# doesn't remove files on the remote host which often leads to undesired results.
#
# The script needs a .git-ftp-rsync file at the root of your git repo and a simple
# line-by-line list of folders you want to sync. The .git-ftp-rsync file is a very
# rudimentary one and does not understand the standard .gitignore syntaxes.
@davidwebca
davidwebca / block-style-locations.php
Last active December 21, 2021 00:38
Block style locations for ACF
<?php
/**
THIS IS NOW A FULL GITHUB REPO: https://github.com/davidwebca/acf-block-style-location
*/
add_filter('acf/location/rule_values/acf_block_style', function ($choices) {