Skip to content

Instantly share code, notes, and snippets.

Avatar

Berkay UNAL berkayunal

View GitHub Profile
View elasticsearch.monit
check process elasticsearch with pidfile /var/run/elasticsearch.pid
start program = "/etc/init.d/elasticsearch start"
stop program = "/etc/init.d/elasticsearch stop"
if 5 restarts within 5 cycles then timeout
if failed host 127.0.0.1 port 9200 type http then restart
@berkayunal
berkayunal / onchange.sh
Created May 17, 2018 — forked from senko/onchange.sh
Watch current directory and execute a command if anything in it changes
View onchange.sh
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <senko.rasic@dobarkod.hr>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of
@berkayunal
berkayunal / mysql_repl_status.sh
Created May 17, 2018 — forked from JGaudette/mysql_repl_status.sh
MySQL Replication Health/Status
View mysql_repl_status.sh
#!/bin/bash
#
# Determine if master and slave mysql servers are in sync
# If not, report it via STDOUT and non-zero return code
# If are in sync, exit successfully
#
# Paramters:
# -v - verbose, show stats even if 100% synchronized
USER='YOUR_USER_NAME'
@berkayunal
berkayunal / .phpstorm.meta.php
Created Mar 29, 2018
Enable autocomplete for CakePHP 3 in PhpStorm
View .phpstorm.meta.php
<?php
namespace PHPSTORM_META;
override(\Cake\ORM\TableRegistry::get(0), map(['' => '\App\Model\Table\@Table']));
@berkayunal
berkayunal / ._ Loading variables from .env files in Ansible.md
Created Jan 16, 2018
Loading variables from .env files in Ansible
View ._ Loading variables from .env files in Ansible.md

Loading variables from .env files in Ansible

Ansible has various ways of looking up data from outside sources, including plain text password files, CSV files and INI files. But it doesn't seem to have a lookup for .env files, as used in Laravel projects, also available for PHP, Ruby, Node.js, Python and others.

One option is to launch Ansible with the Ruby dotenv command line script... But that requires Ruby, which seems like overkill to me.

So here is a simpler solution that I use. It consists of:

  1. The .env file itself
  2. A small shell script that loads the .env file into environment variables - ansible-playbook.sh
@berkayunal
berkayunal / Laravel-Container.md
Created Jan 16, 2018 — forked from davejamesmiller/Laravel-Container.md
Laravel's Dependency Injection Container in Depth
View Laravel-Container.md

Laravel's Dependency Injection Container in Depth

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

Accessing the Container

@berkayunal
berkayunal / web.php
Created Nov 15, 2017
Simple routing for Laravel test controllers
View web.php
<?php
/**
* Routes
*
* Example:
* http://localhost/test/hello/me/param1/param2
* http://localhost/test/hello/there/param1/param2
*/
@berkayunal
berkayunal / Arch Linux, Fedora
Created Oct 17, 2017 — forked from elvetemedve/Arch Linux, Fedora
Allow Vagrant usage without providing sudo password
View Arch Linux, Fedora
sudo tee /etc/sudoers.d/vagrant > /dev/null << EOL
#
# Arch Linux, Fedora sudoers entries
#
# Allow passwordless startup of Vagrant with vagrant-hostsupdater.
Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts
Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/bin/sed -i -e /*/ d /etc/hosts
%sudo ALL=(root) NOPASSWD: VAGRANT_HOSTS_ADD, VAGRANT_HOSTS_REMOVE
@berkayunal
berkayunal / pedantically_commented_playbook.yml
Created Oct 13, 2017 — forked from marktheunissen/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
View pedantically_commented_playbook.yml
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
@berkayunal
berkayunal / Homestead.yaml
Created Oct 11, 2017 — forked from bubba-h57/Homestead.yaml
after.sh for Homestead
View Homestead.yaml
variables:
- key: STS_USER
value: "<your name>"
- key: STS_HOME
value: "<your customized home dir>"
- key: AWS_ACCESS_KEY_ID
value: "<your key>"
- key: AWS_SECRET_ACCESS_KEY
value: "<your secret>"
- key: AWS_DEFAULT_REGION