Skip to content

Instantly share code, notes, and snippets.

View gbrits's full-sized avatar
🤘
Working on something, always.

Grant Brits gbrits

🤘
Working on something, always.
View GitHub Profile
@gbrits
gbrits / laravel-cheat-sheet.php
Last active May 10, 2022 08:21
Laravel Cheat Sheet
// Restricting a model's scope, for tenancy
protected static function boot()
{
parent::boot();
self::addGlobalScope(function(Builder $builder) {
$builder->where('team_id', auth()->user()->current_team_id);
});
}
@gbrits
gbrits / gravityforms_field_labels.php
Last active March 17, 2022 03:34
Replace Entry Keys w/ Admin Labels (GravityForms Webhook Add-on)
<?php
add_filter('gform_webhooks_request_data', function ($request_data, $feed, $entry, $form) {
if (rgars($feed, 'meta/requestBodyType') === 'all_fields') {
foreach ($form['fields'] as $item) {
if ($item->adminLabel != '') {
if (isset($item->inputs) && is_array($item->inputs)) {
if ($item['type'] == 'time') {
foreach ($item->inputs as $key => $input) {
if (isset($entry[floor($input['id'])])) {
if (!is_null($entry[floor($input['id'])])) {
@gbrits
gbrits / maximus_articles_capacitor_2_downgrade.md
Last active February 9, 2022 11:12
Downgrading from Capacitor 3 to Capacitor 2 (for whatever reason)

Step 1.) Delete your iOS, Android & Node modules folder

rm -rf android && rm -rf ios && rm -rf node_modules

Step 2.) Adjust your package.json to include the following:

"@capacitor/android": "^2.4.5",
@gbrits
gbrits / check-country.liquid
Created December 1, 2021 17:08
Country-specific notice (Shopify)
{% if template == 'index' %}
fetch('https://api.ipregistry.co/?key=tryout')
.then(function (response) {
return response.json();
})
.then(function (payload) {
if('Australia' == payload.location.country.name){
$('#international-notice').show();
}
});
@gbrits
gbrits / shopify-canonical.liquid
Created November 3, 2021 12:08
Shopify Trailing Slash (SEO Optimisation)
{% if template contains 'collection' and current_tags %}
<meta name="robots" content="noindex" />
<link rel="canonical" href="{{ shop.url }}{{ collection.url }}" />
{% elsif template contains 'blog' and current_tags %}
<meta name="robots" content="noindex" />
<link rel="canonical" href="{{ shop.url }}{{ blog.url }}" />
{% else %}
{%- if canonical_url != blank -%}
<link rel="canonical" href="{{ canonical_url }}" />
{% endif %}
@gbrits
gbrits / toHHMMSS.js
Created March 16, 2021 06:57
Seconds to hh mm ss
toHHMMSS(secs: number) {
var sec_num = parseInt(Math.abs(secs), 10);
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
if(hours > 0) {
return hours+'h '+minutes+'m '+seconds+'s';
@gbrits
gbrits / kelvin_to_celsius.js
Created October 15, 2020 11:31
Kelvin to Celsius (Javascript)
let kelvin = 288; // Or whatever kelvin
let celsius = ((5/9) * ((Math.floor((Number(kelvin)-273) * (9/5) + 32))-32)).toFixed(0)
@gbrits
gbrits / team.liquid
Created June 30, 2020 02:59
Sorted Iteration by Index
{% assign first_block = content | split: '[team_portfolios]' | first %}
{% assign last_block = content | split: '[team_portfolios]' | last %}
{{ first_block }}
<div class="main-grid-team">
<h1 id="team">Our Team</h1>
<div class="expose-row">
@gbrits
gbrits / get-vars.liquid
Created April 14, 2020 04:23
Shopify $_GET variables via Liquid
<!-- Add this at the top of your page template -->
{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}
{%- assign pageUrl = contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first | split:'.myshopify.com' | last |
replace:'\/','/' |
replace:'%20',' ' |
replace:'\u0026','&'
-%}
{%- unless pageUrl contains "?" -%}{% break %}{%- endunless -%}
{%- assign pageQuerystring = pageUrl | split:'?' | last -%}
@gbrits
gbrits / date-example.php
Created May 16, 2019 02:26
PHP Date with Superscript Ordinal Suffix
<?php
echo date('j<\s\up>S</\s\up> M \'y'); // >= PHP 5.2.2 - 16th Feb '19