Skip to content

Instantly share code, notes, and snippets.

View twfahey1's full-sized avatar

Tyler Fahey twfahey1

View GitHub Profile
@twfahey1
twfahey1 / dates.php
Created April 19, 2022 01:10
Common best PHP dates formats
<?php
/**
These are just reference for common PHP dates.
**/
// 1/1/2022 12:00 PM
$date = date('m/d/Y h:i A');
@twfahey1
twfahey1 / get.php
Created March 8, 2022 21:54
Drupal - Get URL from node
<?php
use Drupal\Core\Url;
$url_options = [
'absolute' => TRUE,
'language' => \Drupal::languageManager()->getCurrentLanguage(),
];
$link = Url::fromRoute('entity.node.canonical', ['node' => $node->id()], $url_options)->toString();
@twfahey1
twfahey1 / uuid.sh
Created January 22, 2022 14:06
Pure bash UUID generator
# Generate a pseudo UUID
uuid()
{
local N B T
for (( N=0; N < 16; ++N ))
do
B=$(( $RANDOM%255 ))
if (( N == 6 ))
@twfahey1
twfahey1 / README.md
Last active November 25, 2023 23:36
Using Google API credentials.json file in Github Action or other scripts

The question: What is the best way we can use Google API via a service account in Github Actions? Answer: encrypt the credentials and decrypt during Action w/ a configured secret.

  • The credentials.json.gpg is originated from the credentials.json that can be downloaded from Cloud Console for the service account.
  • Encrypt it via: gpg --symmetric --cipher-algo AES256 credentials.json - Note the password used, as it will be added as a secret in this repo to be used for decoding the file and accessing Google APIs.
  • Update the credentials.json.gpg file in this repo using the contents of the newly created credentials.json.gpg, commit and push.
  • The password used should be added as a secret, e.g. the GOOGLE_API_PW secret in the github repo

Then, in the Github action or script, call gpg to decrypt and write the unencrypted file:

#!/bin/sh
@twfahey1
twfahey1 / mymodule.links.menu.yml
Created September 1, 2021 04:48
Add a top level admin bar menu route in D8+
@twfahey1
twfahey1 / .zshrc
Created August 18, 2021 11:35
Terminal setup
ZSH_THEME="dracula"
# DRACULA_ARROW_ICON="-> "
parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF='%f'
COLOR_USR='%F{243}'
COLOR_DIR='%F{180}'
COLOR_GIT='%F{39}'
NEWLINE=$'\n'
@twfahey1
twfahey1 / gist:a2f46a2ed8a7b2186b96f58e525eac13
Last active March 30, 2021 16:41
Get JSON:API Extra path prefix config string via php-script terminus for Pantheon site
cat << 'EOF' | terminus drush mysite.dev -- php-script -
$config = \Drupal::config('jsonapi_extras.settings')->get('path_prefix');
echo $config;
EOF
@twfahey1
twfahey1 / clean-git.sh
Created January 26, 2021 16:46
Sanitize all git folders in subdirectories
# Temporarily move current .git to not purge it.
mv .git .gitbackup
mv .gitignore .gitignorebackup
# Purge all gits
find . \( -name ".git" -o -name ".gitignore" -o -name ".gitmodules" -o -name ".gitattributes" \) -exec rm -rf -- {} +
# Put back original git
mv .gitbackup .git
@twfahey1
twfahey1 / get-modules-from-non-composer.sh
Created January 13, 2021 15:07
Script for discovering and requiring Drupal modules via composer
allmodules="";
# Tweak these excluded as needed. Pesky modules, erroneous folders, etc. that are not modules.
# Keep in mind all files in the source folder will be scanned and use in the composer require statement.
excluded=("contrib" "custom" "README.txt" "platform" "config_split")
# Tweak location as needed for wherever script is being run.
for f in $(ls /Users/tylerfahey/Sites/pantheon-sites/wpccu2019/modules); do
# TODO: Check if module is in excluded list and ignore if so.
if [[ " ${excluded[@]} " =~ " ${f} " ]]; then
# whatever you want to do when array contains value
echo "ignoring $f"
Drupal.behaviors.mybehavior = {
attach: function (context, settings) {
$('#some_element', context).once('mybehavior', function () {
// Code here will only be applied to $('#some_element')
// a single time.
});
}
};