Skip to content

Instantly share code, notes, and snippets.

View chrisguitarguy's full-sized avatar

Christopher Davis chrisguitarguy

View GitHub Profile
@chrisguitarguy
chrisguitarguy / rector.php
Created March 28, 2022 18:25
Use rector Replace OpenAPI PHP annotations with Attributes, but note that you'll need to change the namespace from `OpenApi\Annotations` to `OpenApi\Attributes` after this is done.
<?php declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\Symfony\Set\SymfonySetList;
use OpenApi\Annotations as OA;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Serializer\Annotation as Serializer;
<?php
namespace Chrisguitarguy\Example;
use OutOfBoundsException;
use Countable;
use IteratorAggregate;
use Psr\Log\AbstractLogger;
class CollectingLogger extends AbstractLogger implements Countable, IteratorAggregate
@chrisguitarguy
chrisguitarguy / upgrade_migrations.sh
Created February 1, 2020 19:11
Upgrade doctrine migrations to 2.0
#!/usr/bin/env bash
if [ "$#" != 1 ]; then
echo "Usage: $0 {migrationsDirectory}" >&2
exit 1
fi
find "$1" -type f -name '*.php' -exec sed -i '' 's/Doctrine\\DBAL\\Migrations\\AbstractMigration/Doctrine\\Migrations\\AbstractMigration/' {} \;
find "$1" -type f -name '*.php' -exec sed -i '' 's/function up(Schema \$schema)$/function up(Schema $schema) : void/' {} \;
@chrisguitarguy
chrisguitarguy / upgrade_migrations
Created October 9, 2019 18:57
Upgrade doctrine/migrations from 1.X to 2.X
#!/usr/bin/env bash
if [ "$#" != 1 ]; then
echo "Usage: $0 {migrationsDirectory}" >&2
exit 1
fi
find "$1" -type f -name '*.php' -exec sed -i '' 's/Doctrine\\DBAL\\Migrations\\AbstractMigration/Doctrine\\Migrations\\AbstractMigration/' {} \;
find "$1" -type f -name '*.php' -exec sed -i '' 's/function up(Schema \$schema)$/function up(Schema $schema) : void/' {} \;
find "$1" -type f -name '*.php' -exec sed -i '' 's/function down(Schema \$schema)$/function down(Schema $schema) : void/' {} \;
<?php
class ClientDto
{
public $id;
public $name;
public $site_url;
}
#!/usr/bin/env php
<?php
class Token
{
const T_OPEN_PAREN = 1;
const T_CLOSE_PAREN = 2;
const T_IF = 3;
const T_EQ = 4;
const T_PLUS = 5;
@chrisguitarguy
chrisguitarguy / generate_aws_ses_password.php
Created April 26, 2018 20:41
How to generate AWS SES SMTP passwords from an already existing IAM User secret key. In PHP. See https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html#smtp-credentials-convert
<?php
$key = getenv('AWS_SECRET_ACCESS_KEY');
if (!$key) {
throw new \LogicException('Missing AWS_SECRET_ACCESS_KEY');
}
$sig = hash_hmac('sha256', 'SendRawEmail', $key, true);
echo base64_encode(pack('C', 0x02) . $sig), PHP_EOL;
@chrisguitarguy
chrisguitarguy / nginx.conf
Created February 22, 2018 16:22
How to proxy requests from nginx to an upstream backend. Could be use for Python or JavaScript (express) apps.
http {
# other stuff here
# The upstream backend server this can be named whatever you desire
# See http://nginx.org/en/docs/http/ngx_http_upstream_module.html
upstream backend {
# this is the actual hostname + port of the backend server
server backend:8080;
# how many keep alive connections to allow, only set this if you're going
# to specify the `Connection` header in the proxy below, nginx sets the
FROM openjdk:9-jre AS build
## Deps to install DynamoDB
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
coreutils \
ca-certificates \
&& mkdir -p /dynamodb/data
WORKDIR /dynamodb
@chrisguitarguy
chrisguitarguy / all_account_policy.json
Last active January 17, 2019 11:11
Cross Account Redshift UNLOAD/COPY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowS3",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::{REDSHIFT_ACCOUNT_ID}:root"
},
"Action": [