Skip to content

Instantly share code, notes, and snippets.

View matthewpoer's full-sized avatar

Matthew Poer matthewpoer

View GitHub Profile
> ./checkCountryName.sh China
People's Republic of China
@matthewpoer
matthewpoer / directory data.sh
Created January 4, 2020 22:48
Get information about the files within a directory, including list of files, their sizes and md5 hashes.
#/usr/bin/env bash
# for a given directory myDirectory, create a list of all files within that directory
# note that file names are not enclosed in quotes here
find myDirectory -type f -exec echo {} \; > myDirectory.files.text
# if you want them in quotes,
# find myDirectory -type f -exec echo \"{}\" \; > myDirectory.files.text
# and a list of the sizes of each of these files
find myDirectory -type f -exec echo \"{}\" \; | xargs -n1 du -sh > myDirectory.files.sizes.text
@matthewpoer
matthewpoer / DockerKillAll.profile
Last active December 18, 2019 15:12
Docker kill all, Bash alias to stop and remove all Docker containers and images
alias docker_kill_all='docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q) && docker image rm $(docker image ls -q)'
@matthewpoer
matthewpoer / completedAnonymousOrdersFromLastYear.sql
Created December 17, 2019 19:05
Drupal Commerce order, line item and product export from MySQL
SELECT
commerce_order.order_id,
FROM_UNIXTIME(commerce_order.created) AS created,
GROUP_CONCAT(DISTINCT commerce_line_item.line_item_label) AS line_item_label,
GROUP_CONCAT(DISTINCT commerce_product.type) AS productType,
IF(
GROUP_CONCAT(DISTINCT commerce_product.type) = "bundle",
GROUP_CONCAT(DISTINCT bundleProduct.sku),
GROUP_CONCAT(DISTINCT commerce_product.sku)
) AS productSKUList,
@matthewpoer
matthewpoer / .SuiteCRM contactCount Example.md
Last active August 20, 2019 03:16
SuiteCRM Number of Contacts field for Accounts, which will keep an accurate count of the number of Contacts related to the Account. Includes SQL to create the field and seed it once deployed.

SuiteCRM contactCount Example

  1. Run the SQL from fields_meta_data.sql against the database to create the new custom field
  2. Place PHP files into project, locations are noted in comment on each file. Definitions in logic_hooks.php will need to be manually merged into the existing file or else move these definitions to better follow the Extension framework.
  3. Quick Repair and Rebuild
  4. Run the SQL from updateContactCountExistingRecords.sql against the database to populate the new custom field. Note that if custom fields have never been created, then the table accounts_cstm will be empty and this update will fail, you'll need to first populate the table i.e. INSERT INTO accounts_cstm (id_c) SELECT id FROM accounts
@matthewpoer
matthewpoer / clearAllNotifications.sh
Created July 11, 2019 16:00
Acknowledge (Clear) all Heroku Connect notifications for a given Connection
#/usr/bin/env bash
CONNECTION_ID="" # grab from URL for a given HC Connection
TOKEN="" # grab from web requests within Heroku Connect
page=1
keepGoing=1
while [ $keepGoing -gt 0 ]
do
notice_url="https://connect-us.heroku.com/api/v3/connections/${CONNECTION_ID}/notifications?page=${page}"
#!/usr/bin/env bash
PROFILE=yourFavoriteAwsProfile
REGION=us-east-1
TABLE=origin-table
DEST_TABLE=destination-table
TABLE_DUMP=$(aws dynamodb scan --profile ${PROFILE} --region ${REGION} --table-name ${TABLE})
TABLE_Items=`echo ${TABLE_DUMP} | jq -r '.Items'`
#!/usr/bin/env bash
# USD $ 9168.57
curl -s "https://api.coindesk.com/v1/bpi/currentprice.json" | jq .bpi.USD.rate_float | rev | cut -c 3- | rev | xargs echo "USD $"
@matthewpoer
matthewpoer / date_test.php
Created April 17, 2019 18:36
Given a date string, find 1 year out from that date, rounded up or down to the month. Based on a membership renewal cycle requirement.
<?php
function get_date($input) {
$dateObject = new DateTime($input);
if($dateObject->format('d') > 15) $dateObject->modify('+1 month');
$dateObject->modify('first day of'); // set to start of month
$Start_Date__c = $dateObject->format('Y-m-d');
$dateObject->modify('+1 year');
$dateObject->modify('-1 day');
$End_Date__c = $dateObject->format('Y-m-d');
@matthewpoer
matthewpoer / Example.sh
Last active November 1, 2018 17:42
Bash Comments within Multiline Commands
#!/usr/bin/env bash
# https://stackoverflow.com/a/1456019
# https://stackoverflow.com/a/12797512
echo \
`# comment zero` \
'this is a test, ' `# comment one` \
`# comment one point five` \
'this is also a test' `# comment two` \