Skip to content

Instantly share code, notes, and snippets.

@jlabs
jlabs / post_merge
Created March 6, 2024 12:26
Git hook for DDEV + Craft CMS changes on git pull
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
check_run composer.json "ddev composer install"
check_run package.json "ddev npm i"
check_run "/config/project/" "ddev craft project-config/apply"
@jlabs
jlabs / pad.twig
Last active June 23, 2021 10:27
Padding of text in Twig
{#
display the number 9 with 2 0's in front of it
%'_3s would display the number 9 with 2 _ in front
%'%10s with format("123") would display 123 with 7 % in fron of it
% 3s would show 9 and 2 spaces in front
%'_-3s would have 9 then 2 _ after it
%'x-3s would have 2 x's after
#}
@jlabs
jlabs / randrom-array.twig
Created February 1, 2021 09:19
Get random values from an array
{# Get the destinations from an entry query #}
{% set originalArrayQ = craft.entries().section("helloworld") %}
{# Turn the query into an array of results #}
{% set originalArray = originalArrayQ.all() %}
{# Create an empty array #}
{% set r = [] %}
{# Loop through an x amount of count e.g. 0 to 3 (4 values) #}
{% for item in 0..3 %}
{# Merge into the array above a random value from the original array that isn't already in the random (r) array #}
{% set r = r | merge([random(originalArray | filter(v => v not in r))]) %}

Copy and paste the following into Terminal then execute:

defaults write com.apple.dock persistent-apps -array-add '{tile-type="spacer-tile";}'

Copy and paste the following into Termain then execute:

killall Dock

Copy and paste the following into Termain then execute:

exit

Quit Terminal

@jlabs
jlabs / db.php
Last active September 8, 2020 09:52
Fix for MySQL 5.7.5+ and Craft 2.x (see https://craftcms.stackexchange.com/a/12106 for info). Add the comment and the line below the commend to 'config/db.php'
<?php
return array(
// Fix for MySQL 5.7.5+ and Craft 2.x
'initSQLs' => array("SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';")
);
?>
@jlabs
jlabs / sourceTree_device_not_configured.txt
Created August 12, 2020 20:15 — forked from RockinPaul/sourceTree_device_not_configured.txt
SourceTree: Device not configured (on MacOS)
In console:
git config credential.helper
You will see: osxkeychain
git config credential.helper sourcetree
Then if you perform git config credential.helper again
You will see: sourcetree
# ----------------------------------------------------------------------
# | Cleaning URLs |
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
# Remove www from URL's
RewriteCond %{HTTP_HOST} ^www\.(.+)
# RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
<?php
// Array given from 'api'
$arr = array(
"action: Added; quantity: 1; item_code: RNA1; product_name: Mens Organic T-Shirt; colour: White; size: XL;",
"action: Subtracted; quantity: 7; item_code: RNC1; product_name: Kids Basic T-shirt; colour: Denim Blue; size: 3-4y",
"action: Added; quantity: 20; item_code: RNV1; product_name: Gift Voucher; style: Mens; value: £20"
);
// New array to hold the final output
$newArr = array();
Get-AppxProvisionedPackage -online | Where-Object {$_.packagename -like '*officehub*'} | Remove-AppxProvisionedPackage -online
Set-ExecutionPolicy RemoteSigned
# Prompt for the account name
$username = Read-Host "Account name"
# Get the current expiry date
$accexp = Get-LocalUser -Name $username | select AccountExpires
# Display the account name with the expiry date in a easy to read format
Write-Host "Account " -NoNewline; Write-Host $username -BackgroundColor White -ForegroundColor Black -NoNewline; Write-Host " is " -NoNewline; Write-Host $accexp.AccountExpires -BackgroundColor White -ForegroundColor Black
# Get a new expiry
$newexp = Read-Host "Enter new expiry"
# Set the new expiry