Skip to content

Instantly share code, notes, and snippets.

View davidwebca's full-sized avatar

David Lapointe Gilbert davidwebca

View GitHub Profile
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 /
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 --output
davidwebca / JsondTwigExtension.php
Last active March 17, 2023 13:28
JsondTwigExtension to fix some weird json_encode issues
* Based on Indigo Viking's Twig Extension
* @see
namespace modules\twigextensions;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
davidwebca /
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 / fix-woo-learndash-sub-rollback.php
Created September 26, 2022 21:24
Fix learndash_woocommerce.php + WooCommerce Subscription rollback issue
* Theme filters.
namespace App;
* Fix checkout bug with learndash_woocommerce
* learndash_woocommerce.php:580
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
* 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
* @see
davidwebca / post-ftp-push
Last active December 11, 2023 16:01
git-ftp rsync hook
# 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 / block-style-locations.php
Last active December 21, 2021 00:38
Block style locations for ACF
add_filter('acf/location/rule_values/acf_block_style', function ($choices) {
davidwebca /
Last active December 9, 2021 05:15
Tailwind JIT Dynamic Scoping

Tailwind Dynamic Scoping

This is a quick and dirty simple method to allow dynamic scoping in Tailwind CSS. It happens on-the-fly thanks to the JIT engine and doesn't need any new config when you want to add a new scope.

Generate this

.admin .scope-\[\.admin\|bg-red-500\+underline\] {
  --tw-bg-opacity: 1;
 background-color: rgb(239 68 68 / var(--tw-bg-opacity));
davidwebca / pllstrings.php
Created June 1, 2021 13:46
Translate regular gettext and underscore functions with Polylang's strings
add_filter('gettext', function($translation, $text, $domain) {
if(is_admin()) {
return $translation;
if($domain == 'mythemedomain') {
$slug = sanitize_title($text);
icl_register_string($domain, $slug, $text);