Skip to content

Instantly share code, notes, and snippets.

@2ec0b4
2ec0b4 / listener.php
Created December 13, 2019 10:38
PostgreSQL Notifier with a PHP Listener
<?php
set_time_limit(0);
$db = new PDO(
'pgsql:dbname=dbname host=host port=5432;options=--application_name=APPLICATION_NAME',
'user',
'password',
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
@2ec0b4
2ec0b4 / watch.sh
Created February 27, 2019 13:28
Watch for file changes and do something
#!/bin/bash
# This script requires [entr](http://entrproject.org): `brew install entr`
# Tested on macOS Mojave
while true; do
# Watch for files changes or new files in the current directory, except in ./dist, ./vendor and ./.git, and execute ./do-something.sh
find . \( -path "./dist" -o -path "./vendor" -o -path "./.git" \) -prune -o -print | entr -d ./do-something.sh
done
@2ec0b4
2ec0b4 / deploy.md
Last active January 9, 2018 09:29
Déploiement avec Capistrano

Déploiement avec Capistrano

Le déploiement est lancé depuis une box Vagrant disposant de Ruby >= 2.0. Dans le gestionnaire de paquets RubyGem, il faut penser à ajouter capistrano.

Configuration sur le serveur distant

Pré-requis

  • Git
@2ec0b4
2ec0b4 / Vagantfile
Created April 20, 2016 20:25
vagrant push staging
Vagrant.configure('2') do |config|
config.push.define "staging", strategy: "ftp" do |push|
push.host = "staging.dev"
push.passive = false
push.secure = true
push.username = "user"
push.password = "password"
push.destination = "/var/www/staging/"
push.dir = "./html/"
end
@2ec0b4
2ec0b4 / myservice
Last active May 8, 2017 12:48 — forked from bramus/myservice
Running a PHP script as a service/daemon using `start-stop-daemon`
#! /bin/sh
# Installation
# - Move this to /etc/init.d/myservice
# - chmod +x this
#
# Starting and stopping
# - Start: `service myservice start` or `/etc/init.d/myservice start`
# - Stop: `service myservice stop` or `/etc/init.d/myservice stop`
@2ec0b4
2ec0b4 / lights.climagic.sh
Created November 21, 2015 21:43
KITT grill visual from Knight Rider
#!/bin/bash
vNbLights=9
vWidth=3
vSleep=0.5
function sendRequest() {
nc -w0 -u lights.climagic.com 45444 <<< $1
}
@2ec0b4
2ec0b4 / convert-bytes.php
Created November 1, 2014 14:53
Convert bytes
<?php
/**
* Convert bytes
* @param int|string $bytes
* @return mixed returns an array with the converted value and a label key (see $unit)
*/
function convert_bytes($bytes)
{
$unit = array(
@2ec0b4
2ec0b4 / last-modified-files.sh
Created November 1, 2014 14:53
Find the 10 last modified files of a directory
#!/bin/bash
cd /path/to/dir/
find . -type f -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -10 | cut -f2- -d" "
# or with modification time
find . -type f -print0 | xargs -0 stat -f "%m %t%Sm %N" | sort -rn | head -10 | cut -f2-
@2ec0b4
2ec0b4 / change-permissions.sh
Created November 1, 2014 14:52
Recursively change the access permissions to directories and files
#!/bin/bash
cd /path/to/dir/
find . -type d -exec chmod 755 {} +
find . -type f -exec chmod 644 {} +