Skip to content

Instantly share code, notes, and snippets.

@sshymko
sshymko / aws_codepipeline_lambda_invalidate_cloudfront.js
Last active Jan 9, 2021
Invalidate CloudFront distribution from CodePipeline via Lambda function
View aws_codepipeline_lambda_invalidate_cloudfront.js
const aws = require('aws-sdk');
const codepipeline = new aws.CodePipeline();
const cloudfront = new aws.CloudFront();
exports.handler = async (event, context) => {
let job = event['CodePipeline.job'];
let config = job.data.actionConfiguration.configuration.UserParameters;
try {
let params = JSON.parse(config);
if (!params || !params.distributionId) {
@sshymko
sshymko / install_php_pecl_ssh2.sh
Created Oct 14, 2020
Install SSH2 PHP7 extension on Amazon Linux 2
View install_php_pecl_ssh2.sh
#!/bin/sh
sudo yum install php-pecl-ssh2 -y
@sshymko
sshymko / buildspec.yml
Created Aug 27, 2020
AWS CodeBuild specification for single-page application (SPA) managed by NPM
View buildspec.yml
version: 0.2
phases:
install:
runtime-versions:
nodejs: 12
build:
commands:
- npm install
- npm run build -- --mode=production
@sshymko
sshymko / Dockerfile
Last active Aug 25, 2020
Docker PHP with OPcache and Swoole extension & OpenSSL support
View Dockerfile
FROM php:7.4-cli
ARG SWOOLE_VERSION=swoole
RUN apt-get update -q
RUN apt-get install -y --no-install-recommends \
libssl-dev
RUN docker-php-ext-install \
opcache
@sshymko
sshymko / install_pecl_imagick_amzn2.sh
Last active Apr 13, 2021
Install latest ImageMagick 7.x and imagick PHP extension from PECL on Amazon Linux 2
View install_pecl_imagick_amzn2.sh
#!/bin/sh
# Uninstall ImageMagic library and imagick PHP extension using it (installed previously)
yum remove -y php-pecl-imagick ImageMagick
# Install libraries for JPG, PNG, GIF, WebP, and TIFF image formats
yum install -y libpng-devel libjpeg-devel openjpeg2-devel libtiff-devel libwebp-devel giflib-devel
# Install latest ImageMagick library compiled from downloaded sources
yum install -y gcc
@sshymko
sshymko / throwable_chaining.php
Created Feb 15, 2020
Chaining of immutable throwable exceptions/errors (PHP8 proposal)
View throwable_chaining.php
<?php
interface Throwable
{
/**
* Return immutable copy with causal chain extended by given root cause
*
* @return Throwable
*/
public function chain(Throwable $cause = null): Throwable;
@sshymko
sshymko / overload.php
Last active Feb 16, 2020
PHP7 function/method signature overloading
View overload.php
<?php
declare(strict_types=1);
function overload(callable ...$implementations): callable
{
return function (...$args) use ($implementations) {
$error = new \LogicException('Invalid overloaded implementations');
foreach ($implementations as $candidate) {
try {
return $candidate(...$args);
@sshymko
sshymko / only.sh
Last active Jan 29, 2020
Wrapper launching single process using its execution permission as concurrency semaphore
View only.sh
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $0 <command> [args...]"
exit
fi
trap ':' SIGINT SIGTERM
chmod u-x "$0"
@sshymko
sshymko / install_nginx_php7_amzn2_remi.sh
Last active Apr 16, 2021
Install Nginx and PHP-FPM on Amazon Linux 2 from REMI repository
View install_nginx_php7_amzn2_remi.sh
#!/bin/sh
sudo yum update -y
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --setopt="remi-php72.priority=5" --enable remi-php72
sudo yum install -y nginx
sudo systemctl enable nginx
@sshymko
sshymko / install_nginx_php7_amzn2_extra.sh
Last active Jul 23, 2020
Install Nginx and PHP-FPM on Amazon Linux 2 from Amazon Linux Extras
View install_nginx_php7_amzn2_extra.sh
#!/bin/sh
sudo yum update -y
sudo amazon-linux-extras install -y epel
sudo amazon-linux-extras install -y php7.2
sudo yum install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx