Skip to content

Instantly share code, notes, and snippets.

in docker-compose.yml:
nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
extra_hosts:
# requires `export DOCKERHOST="$(ifconfig en0 inet | grep "inet " | awk -F'[: ]+' '{ print $2 }')"` in ~/.bash_profile
- "dockerhost:$DOCKERHOST"
@mikemadisonweb
mikemadisonweb / Vagrantfile
Last active December 12, 2016 06:44
Vagrantfile advanced config with instant file synchronization, config merging and auto hostname managing (Yii2)
require 'yaml'
require 'fileutils'
config = {
local: './vagrant/vagrant-local.yml',
main: './vagrant/vagrant-main.yml'
}
# Копирование и чтение конфига из файла
FileUtils.cp config[:main], config[:local] unless File.exist?(config[:local])
@mikemadisonweb
mikemadisonweb / DateIntervals.php
Last active December 2, 2016 10:38
Class DateIntervals - helper class to compute and format human readable date intervals , e.g. 1 hour 5 minutes 24 seconds
<?php
/**
* Helper class to compute human readable date intervals , e.g. 1 hour 5 minutes 24 seconds
*/
class DateIntervals
{
private $forms = [
'eng' => [
'years' => ['year', 'years'],
mysql --database=dbname -B -N -e "SHOW FULL TABLES WHERE Table_Type = 'BASE TABLE'" | awk '{print "ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"}' | mysql --database=dbname &
@mikemadisonweb
mikemadisonweb / OneInstance.php
Last active December 2, 2016 10:32 — forked from m8rge/CronException.php
Yii2 console controller behavior. Prevents double run console command
<?php
namespace console\controllers\behaviors;
use Yii;
use yii\base\ActionEvent;
use yii\base\Behavior;
use yii\base\Exception;
use yii\console\Controller;
@mikemadisonweb
mikemadisonweb / TruncateString.php
Created November 3, 2016 06:51 — forked from m8rge/TruncateString.php
Truncate string on word break
<?php
/**
* @param string $string Subject
* @param int $length Max string length
* @param bool $exactLength Truncate string with exact $length
* @param string $append Ellipsis string
* @return string
*/
class TruncateString
@mikemadisonweb
mikemadisonweb / ConsoleProgress.php
Created November 3, 2016 06:50 — forked from m8rge/ConsoleProgress.php
Simple yii2 console progress helper
<?php
use yii\base\Object;
use yii\helpers\Console;
/**
* Usage:
* $consoleProgress = new ConsoleProgress(['max' => 365]);
* $consoleProgress->start();
* foreach($days in $day) {
@mikemadisonweb
mikemadisonweb / ansible_conditionals_examples.yaml
Created October 19, 2016 15:19 — forked from marcusphi/ansible_conditionals_examples.yaml
Ansible 1.3 Conditional Execution -- Very complete example with comments -- I find the conditional expressions to be ridiculously hard to get right in Ansible. I don't have a good model of what's going on under the surface so I often get it wrong. What makes it even harder is that there has been at least three different variants over the course …
---
# This has been tested with ansible 1.3 with these commands:
# ansible-playbook -i hosts ansible_conditionals_examples.yaml --extra-vars="hosts=myhosts isFirstRun=false"
# ansible-playbook -i hosts ansible_conditionals_examples.yaml --extra-vars="hosts=myhosts isFirstRun=true"
# ansible-playbook -i hosts ansible_conditionals_examples.yaml --extra-vars="hosts=myhosts"
# NB: The type of the variable is crucial!
- name: Ansible Conditionals Examples
hosts: $hosts
vars_files:
@mikemadisonweb
mikemadisonweb / supervisord-example.conf
Created October 18, 2016 11:46 — forked from didip/supervisord-example.conf
Example configuration file for supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
nodaemon=false ; run supervisord as a daemon