Skip to content

Instantly share code, notes, and snippets.

@stefanotorresi
stefanotorresi / ansible-playbook.yml
Created April 7, 2016 11:46
Wordpress theme deployment and development with Ansible, Composer and wp-cli
---
- hosts: wordpress-server
vars:
root_directory: /var/www/html
theme_name: your-theme-name
theme_repo: https://yourtheme.git.url.git
locale: it_IT
url: http://absolute-url.tld
title: Worpdress
admin_user: admin
@stefanotorresi
stefanotorresi / disk-space-check.sh
Last active May 25, 2016 13:36
check disk space left and send email warning
#!/bin/bash
ADMIN="[email protected]"
# set alert-level %
ALERT=85
MAILER=/usr/bin/mail
df -Ph | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
@stefanotorresi
stefanotorresi / .gitignore
Last active November 5, 2021 07:43
Playing with Python asyncio and websockets
env
#!/usr/bin/env bash
composer install --no-dev
for DEP in $(composer show -N); do
echo
echo "*** downgrading ${DEP} ***"
echo
composer update $DEP --prefer-lowest --prefer-stable
composer test
TEST_FAILED=$?
if [[ $TEST_FAILED -gt 0 ]]; then
@stefanotorresi
stefanotorresi / config.php
Created March 22, 2017 15:04
Psysh default config that adds Composer autoloader automagically. Save it in `~/.config/psysh`.
<?php
$defaultIncludes = [];
$composerAutoload = getcwd() . DIRECTORY_SEPARATOR . '/vendor/autoload.php';
if (is_file($composerAutoload)) {
$defaultIncludes[] = $composerAutoload;
}
return [
@stefanotorresi
stefanotorresi / amp-process.php
Created July 21, 2017 21:22
Run multiple processes concurrently with amphp/process and coroutines
<?php
declare(strict_types=1);
use Amp\ByteStream\Message;
use Amp\Loop;
use Amp\Process\Process;
use function Amp\coroutine;
use function Amp\Promise\all;
@stefanotorresi
stefanotorresi / databases.sh
Last active February 1, 2018 07:52
Initialising multiple databases inside a Docker MySQL image
#!/usr/bin/env bash
# ** usage **
# initialize a MYSQL_DATABASES env variable in the container with space separated db names
# e.g. MYSQL_DATABASES="foo bar"
# assumes that MYSQL_ROOT_PASSWORD and MYSQL_USER are set
function create_database() {
local DATABASE=$1
@stefanotorresi
stefanotorresi / Psr15MiddlewareFromAnonFunc.php
Last active February 7, 2018 09:28
How to use old style single pass anonymous function middleware with the PSR-15 spec.
<?php
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Server\RequestHandlerInterface as Handler;
use Psr\Http\Server\MiddlewareInterface as Middleware;
$middleware = function(Request $req, callable $next): Response {
$res = $next($req);
return $res->withHeader('X-Foo', 'Bar');
@stefanotorresi
stefanotorresi / composer.json
Created February 17, 2018 12:17
Barebone example of a PSR-15 middleware stack.
{
"require": {
"psr/http-server-middleware": "^1.0",
"zendframework/zend-diactoros": "^1.7"
}
}
@stefanotorresi
stefanotorresi / clean-up-generated-droplets
Created September 28, 2018 12:17
Gitlab CI runner cleanup script
#!/bin/bash
set -euo pipefail
export PATH=$PATH:/usr/local/bin:/usr/local/sbin
echo "*****"
date +%F\ %T
echo "stopping gitlab-runner service..."