Skip to content

Instantly share code, notes, and snippets.

View Daveiano's full-sized avatar
🏠
Working from home

Daveiano

🏠
Working from home
View GitHub Profile
@Daveiano
Daveiano / commandline.py
Created May 1, 2023 09:39 — forked from opie4624/commandline.py
Base Python Command Line template
#!/usr/bin/env python
#
# import modules used here -- sys is a very standard one
import sys, argparse, logging
# Gather our code in a main() function
def main(args, loglevel):
logging.basicConfig(format="%(levelname)s: %(message)s", level=loglevel)
@Daveiano
Daveiano / request.php
Created February 11, 2019 13:06
Drupal 8 Request in php
<?php
try {
$response = \Drupal::httpClient()->get($_SERVER['HTTP_HOST'] . '/jsonapi/node/xxx');
$data = (string) $response->getBody();
if (empty($data)) {
return FALSE;
}
}
catch (RequestException $e) {
@Daveiano
Daveiano / SubRequestController.php
Last active February 28, 2020 21:24 — forked from dmouse/SubRequestController.php
Drupal 8: how to create a sub-request
<?php
namespace Drupal\content_helper\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
/**
@Daveiano
Daveiano / sync-s3.sh
Created January 21, 2019 22:32
Basic Sync Script for AWS S3 for a static website bucket with Cloudfront Cache invalidation
#!/bin/bash
# Should be in Format: Wed, 21 Oct 2015 07:28:00 GMT
expire_date=$(date +"%a, %d %b %Y 16:00:00 GMT" -d '+ 1 month')
# Sync Assets, max-age = 1 month, expires header set now + 1 month
aws s3 sync ./.. s3://<bucket> --exclude '*' --include 'favicon.ico' --include 'dist/*' --include 'index.html' --cache-control 'public, max-age=2592000' --expires "$expire_date" --delete
# Cloudfront Cache Invalidation
aws cloudfront create-invalidation --distribution-id <ID> --paths '/*'