Skip to content

Instantly share code, notes, and snippets.

@tommy-muehle
tommy-muehle / .sql
Created February 15, 2019 07:45
PostgreSQL Index Usage Analysis
SELECT
relname AS TableName,
to_char(seq_scan, '999,999,999,999') AS TotalSeqScan,
to_char(idx_scan, '999,999,999,999') AS TotalIndexScan,
to_char(n_live_tup, '999,999,999,999') AS TableRows,
pg_size_pretty(pg_relation_size(relname :: regclass)) AS TableSize
FROM pg_stat_all_tables
WHERE schemaname = 'public'
AND 50 * seq_scan > idx_scan -- more then 2%
AND n_live_tup > 10000
@tommy-muehle
tommy-muehle / Dockerfile
Created August 14, 2018 07:50
PHP alpine example
FROM alpine:3.7
MAINTAINER Tommy Muehle <tommy.muehle@gmail.com>
ENV COMPOSER_HOME /composer
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV PATH /composer/vendor/bin:$PATH
RUN apk --update --progress --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.7/community add \
curl \
php7 \
@tommy-muehle
tommy-muehle / dispatcher.go
Last active October 27, 2019 15:10
Event dispatcher
package events
import (
"sync"
"context"
)
type Dispatcher struct {
mutex *sync.RWMutex
listeners map[string][]Listener
@tommy-muehle
tommy-muehle / main.go
Created January 4, 2018 09:15
PubSub subscription example
package main
import (
"context"
"log"
"cloud.google.com/go/pubsub"
)
func main() {
@tommy-muehle
tommy-muehle / CacheWarmer.php
Last active September 18, 2017 09:45
Gist's for better testing article
<?php
namespace My\App;
class CacheWarmer
{
private $cacheDirectory;
public function __construct(string $cacheDirectory)
{
@tommy-muehle
tommy-muehle / php.ini
Created March 22, 2017 09:07
php.ini
[PHP]
;;;;;;;;;;;;;;;;;;;
; About php.ini ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.
; PHP attempts to find and load this configuration from a number of locations.
; The following is a summary of its search order:
@tommy-muehle
tommy-muehle / performance-tester.php
Last active January 5, 2017 14:05
Wrapper to simulate a "composer run-script post-update-cmd" to start tooly-composer-script's script handler. The standard way "blackfire run composer run-script post-install-cmd" only returns a big passthru. (https://blackfire.io/profiles/4013cbc8-af9d-49ba-83ac-becc921a322b/graph?settings%5Bdimension%5D=wt&settings%5Bdisplay%5D=landscape&settin…
<?php
require __DIR__ . '/../vendor/autoload.php';
use Composer\Script\Event;
use Composer\IO\ConsoleIO;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Helper\HelperSet;
use Tooly\ScriptHandler;
@tommy-muehle
tommy-muehle / scare.sh
Last active July 1, 2016 13:50
admin-scare | Usage: .bashrc ./scare.sh
#!/bin/bash
messages=("Encrypt / ... Waiting" "Create bitcoin ... Waiting" "Format disk ... Waiting" "Copy all emails ... Waiting" "Update passwords ... Waiting")
echo ${messages[$RANDOM % ${#messages[@]} ]}
sleep 2000
@tommy-muehle
tommy-muehle / post-receive
Last active May 24, 2019 09:53
Git hook to auto-merge hotfix branches
#!/usr/bin/env bash
while read oldrev newrev refname
do
BRANCH=$(git rev-parse --symbolic --abbrev-ref $refname)
if [[ "$BRANCH" =~ ^hotfix/* ]]; then
echo " /==============================="
echo " | HOTFIX DETECTED ..."
GIT_WORK_TREE=/tmp git checkout master -f -q
GIT_WORK_TREE=/tmp git merge $BRANCH -q --comit -m "Merge $BRANCH" --no-ff
@tommy-muehle
tommy-muehle / composer
Last active May 10, 2016 08:41
/usr/local/bin/composer
#!/usr/bin/env bash
PHP=/usr/local/opt/php70/bin/php
ARGUMENTS="--ignore-platform-reqs --optimize-autoloader"
EXCLUDE_COMMANDS=(init selfupdate dumpautoload diagnose)
for item in "${EXCLUDE_COMMANDS[@]}"; do
if [[ $1 == "$item" ]]; then ARGUMENTS=""; fi
done
echo "Running composer with $($PHP -v)"