Skip to content

Instantly share code, notes, and snippets.

View drobinson's full-sized avatar

David Robinson drobinson

View GitHub Profile
@drobinson
drobinson / prepare-commit-msg
Created May 12, 2023 15:18
Prepend the ticket number from current branch to commit message
#!/bin/sh
# Put this in .git/hooks/
# Get current branch
branchName=`git rev-parse --abbrev-ref HEAD`
echo "branchName: $branchName" >&2
# Match Jira issue ID in a pattern such as "{any_word}/abc-123-description" or "ABC-123-description"
jiraId=$(echo $branchName | sed -Ene 's,^([a-zA-Z0-9_/-]+/)?([a-zA-Z]+-[0-9]+)-.+,\2,p')
@drobinson
drobinson / prepare-commit-msg
Created December 12, 2022 18:50
Prepend commit message with Jira ticket number from the current branch
#!/bin/sh
# Put this file in .git/hooks/ to prepend all commit messages with the
# Jira ticket number found in the current branch name
# modified from https://community.atlassian.com/t5/Bitbucket-questions/automatically-append-JIRA-issue-ID-into-commit-message/qaq-p/605991#M24736
# get current branch
branchName=`git rev-parse --abbrev-ref HEAD`
@drobinson
drobinson / awsSignatureVersion4.php
Last active August 25, 2020 23:06
Quick PHP implementation of AWS Signature Version 4 docs example request
<?php
// See docs here: https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
// running example here: https://3v4l.org/E3oBG
$body = '';
$bodyHash = hash('sha256', $body);
$canonicalRequest = <<<HEREDOC
GET
[
{
"author": "Chinua Achebe",
"country": "Nigeria",
"imageLink": "images/things-fall-apart.jpg",
"language": "English",
"link": "https://en.wikipedia.org/wiki/Things_Fall_Apart\n",
"pages": 209,
"title": "Things Fall Apart",
"year": 1958
@drobinson
drobinson / thingofbeauty.php
Last active November 30, 2022 20:16
This code runs.
<?php
$this->getSelect()->group('main_table.giftvoucher_id')->joinLeft(
array('history' => $this->getTable('giftvoucher/history')),
'main_table.giftvoucher_id = history.giftvoucher_id', array(
'history_amount' => 'amount',
'history_currency' => 'currency',
'created_at',
'extra_content',
'order_increment_id'
@drobinson
drobinson / readnewestfile.sh
Created May 31, 2018 16:25
Opens the newest file in a directory with less - used for reading var/report logs in Magento
ls -t | head -n1 | xargs -n1 less
@drobinson
drobinson / payments_select.sql
Created April 7, 2018 18:33
Simple historical payment information report by month
select year(sfo.created_at) as year, monthname(sfo.created_at) as month, method, count(sfop.entity_id) as orders, round(sum(amount_paid), 2) as total_revenue from sales_flat_order_payment as sfop
left join sales_flat_order as sfo on sfop.parent_id = sfo.entity_id
group by year(sfo.created_at), month(sfo.created_at), method
@drobinson
drobinson / 1.9.2.3-php7support.diff
Created January 29, 2016 20:38
Diff for PHP 7 support in Magento CE 1.9.2.3
diff --git a/app/code/core/Mage/Core/Model/Layout.php b/app/code/core/Mage/Core/Model/Layout.php
index cb9227b..f61a462 100644
--- a/app/code/core/Mage/Core/Model/Layout.php
+++ b/app/code/core/Mage/Core/Model/Layout.php
@@ -552,7 +552,7 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
$out = '';
if (!empty($this->_output)) {
foreach ($this->_output as $callback) {
- $out .= $this->getBlock($callback[0])->$callback[1]();
+ $out .= $this->getBlock($callback[0])->{$callback[1]}();
--- a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Option/Collection.php
+++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Option/Collection.php
@@ -114,7 +114,7 @@ class Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection extends Mage_Co
*/
public function setIdFilter($optionId)
{
- return $this->addFieldToFilter('option_id', array('in' => $optionId));
+ return $this->addFieldToFilter('main_table.option_id', array('in' => $optionId));
}
@drobinson
drobinson / diff-filter.md
Created July 13, 2015 21:20
Filter git diff by change type

--diff-filter=[ACDMRTUXB*]

Select only files that are

  • A Added
  • C Copied
  • D Deleted
  • M Modified
  • R Renamed
  • T have their type (mode) changed