Skip to content

Instantly share code, notes, and snippets.

@berkayunal
berkayunal / elasticsearch.monit
Created May 17, 2018 18:30 — forked from gacha/elasticsearch.monit
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 18:12 — forked from senko/onchange.sh
Watch current directory and execute a command if anything in it changes
#!/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 18:08 — forked from JGaudette/mysql_repl_status.sh
MySQL Replication Health/Status
#!/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 March 29, 2018 12:48
Enable autocomplete for CakePHP 3 in PhpStorm
<?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 January 16, 2018 20:42
Loading variables from .env files in Ansible

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 January 16, 2018 20:41
Laravel's Dependency Injection Container in Depth

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 November 15, 2017 12:36
Simple routing for Laravel test controllers
<?php
/**
* Routes
*
* Example:
* http://localhost/test/hello/me/param1/param2
* http://localhost/test/hello/there/param1/param2
*/
@berkayunal
berkayunal / Arch Linux, Fedora
Created October 17, 2017 11:42 — forked from elvetemedve/Arch Linux, Fedora
Allow Vagrant usage without providing sudo password
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 October 13, 2017 13:39 — forked from marktheunissen/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ 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 October 11, 2017 15:45 — forked from bubba-h57/Homestead.yaml
after.sh for Homestead
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