Skip to content

Instantly share code, notes, and snippets.

View purdy's full-sized avatar

Jason Purdy purdy

View GitHub Profile
@purdy
purdy / pre-commit.php
Created May 28, 2022 21:40
This is a file named pre-commit that we use in our repo's ~/.git/hooks to check our php code
#!/usr/bin/env php
<?php
// Credit: https://carlosbuenosvinos.com/write-your-git-hooks-in-php-and-keep-them-under-git-control/
require __DIR__ . '/../../vendor/autoload.php';
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<!--[if gte mso 9]><xml><o:OfficeDocumentSettings><o:AllowPNG/><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml><![endif]-->
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<meta content="width=device-width" name="viewport"/>
<!--[if !mso]><!-->
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<!--<![endif]-->
@purdy
purdy / config.yml
Created April 22, 2019 12:26
This is our circleci config.yml file
# This is Journalistic's A&O CI workflow. Whenever we push code to github
# that's not the master branch, it needs to download the branch, push it up to
# Pantheon, create a CI environment, run the visual regression testing, and
# then run the cypress testing.
defaults: &defaults
docker:
- image: quay.io/pantheon-public/build-tools-ci:4.x
working_directory: ~/app
environment:
@purdy
purdy / build-master-lite.sh
Created April 18, 2019 14:39
Pantheon build script for master-lite environment
#!/bin/bash
# This is a daily script to build an updated master-lite database for our various pubs.
for site in site1 site2 site3
do
echo "Building master-lite for $site"
# First, make sure the master-lite env is woke.
echo "Making sure master-lite environment is woke - $site."
@purdy
purdy / index.js
Created August 23, 2018 19:00
This is the Lambda function for taking SNS messages from SES and saving them into a DynamoDB table.
var aws = require('aws-sdk');
var ddb = new aws.DynamoDB({
params: {
TableName: process.env.ddb_table_name
}
});
exports.handler = function(event, context, callback) {
var result = true;
for (var i=0, len = event.Records.length; i < len; i++) {
saveToDynamoDB(event.Records[i], context);
@purdy
purdy / aws-sns-lambda-example.json
Created August 15, 2018 20:01
Example event from SNS when posting to Lambda
{
"Records": [
{
"EventSource": "aws:sns",
"EventVersion": "1.0",
"EventSubscriptionArn": "arn:aws:sns:us-east-1:123412341234:LambdaTesting:12b6a0a7-bbbb-ffff-cccc-7a7d21e25123",
"Sns": {
"Type": "Notification",
"MessageId": "614a0b34-bbbb-ffff-cccc-58ffddd9745f",
"TopicArn": "arn:aws:sns:us-east-1:123412341234:LambdaTesting",
@purdy
purdy / send-email.php
Last active September 15, 2017 02:40
<?php
/**
* Quick utility script to send email out ... before you send this out,
* run this to load up the Sendgrid API key into your environment:
* source ./sendgrid.env
*
* Also, this code uses composer and the sendgrid/sendgrid library:
* composer require sendgrid/sendgrid
*/
@purdy
purdy / confirm_form_example.module
Created April 14, 2014 21:12
confirm_form module example
<?php
/**
* @file
* confirm form example module
*
* */
function confirm_form_example_menu() {
$items['confirm_form_example_delete_object'] = array(
@purdy
purdy / gist:3919058
Created October 19, 2012 16:07
Drupal drupal_write_record() recipe
function MYFORM_submit( $form, &$form_state ) {
$msg = '';
$msg_type = 'status';
$redirect = 'admin/MYMODULE/INDEX_PATH';
$action = 'save your changes';
$expected = SAVED_UPDATED;
$update_msg = 'Your changes to the %category category have been saved.';
if ( is_numeric( $form_state['values']['id'] ) ) {
$TABLE_DATA['id'] = $form_state['values']['id'];
$result = drupal_write_record( 'MYTABLE', $TABLE_DATA, 'id' );