Skip to content

Instantly share code, notes, and snippets.

@dgpro
dgpro / laravel-tail.sh
Created April 1, 2019 09:17
SSH Script to tail the latest Laravel log files on remote server
#!/bin/bash
# exit if any of the commands fail
set -e
source ${BASH_SOURCE[0]%/*}/ip.conf
today=$(date +"%Y-%m-%d")
echo -e "Connecting to ip:$ip";
@dgpro
dgpro / remote-sftp.sh
Created April 1, 2019 09:15
SSH Script to connect to remote SFTP server
#!/bin/bash
# exit if any of the commands fail
set -e
source ${BASH_SOURCE[0]%/*}/ip.conf
echo -e "Connecting to ip:$ip";
sftp username@$ip
@dgpro
dgpro / import-latest-backup.sh
Last active April 1, 2019 09:14
SSH Script to import the latest backup file from remote server
#!/bin/bash
# import ip config
source ${BASH_SOURCE[0]%/*}/ip.conf
ssh root@$ip ls -t /root/backups/*backup.gz | head -n1 | awk '{printf("%s",$0)}' | cat > backup.gz
@dgpro
dgpro / remote_servers.sh
Created April 1, 2019 09:07
SSH Script to automatically run a number of commands on remote servers. E.g. to restart Laravel instance
#!/bin/bash
# exit if any of the commands fail
set -e
# import config with IP addresses
source ${BASH_SOURCE[0]%/*}/ip.conf
echo -e "Connecting to IP:$laravel";
ssh root@$worker -t "cd /var/www/ &&
@dgpro
dgpro / cleanup.sh
Last active April 1, 2019 09:01
SSH Script to cleanup folder space by removing older files. E.g. for backups
#!/bin/bash
# directory to cleanup
DIR=$1
# how much to free up in Gb
SIZE=$2
# factor to size conversion
FACTOR=1048576
MAX_FREE_SIZE=20
@dgpro
dgpro / jQuery-Checkbox-Toggle.html
Created January 31, 2019 16:20
jQuery Checkbox Toggle Show/Hide Elements
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$(function () {
// Show and hide filter block based on selected checkbox toggle-source
function toggleFilters(name, delay) {
delay = delay || 0;
if ($('input[name=' + name + ']').is(':checked')) {
$('.hide-when-' + name).fadeOut(delay)
$('.show-when-' + name).delay(delay).fadeIn(delay)
} else {
@dgpro
dgpro / error_handler.php
Last active April 11, 2018 16:29
PHP handle errors on shutdown and send by email
<?php
error_reporting(E_ALL & ~ E_NOTICE);
set_error_handler('my_error_handler');
register_shutdown_function('send_error_log');
$__errors = array();
function my_error_handler($code, $message, $file, $line)
{
if (!(error_reporting() & $code)) {
// This error code is not included in error_reporting
@dgpro
dgpro / regex-phpdoc-class-properties-to-one-line.md
Last active February 16, 2018 12:52
Convert PHPDoc Class Variables Properties into One Line

Convert PHPDoc Class Variables Properties into One Line

Regular expression:

pattern: (/\*\*)\n\s*\*\s*(\@var.*)\n\s*(\*/)

replacement: $1 $2 $3

It will convert this:

@dgpro
dgpro / guplfile.js
Created October 18, 2017 14:58
Gulp using Bower main files (jquery, bootstrap and etc) with merging less and css example
var gulp = require('gulp'),
filter = require('gulp-filter'),
mainBowerFiles = require('main-bower-files'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
cleanCss = require('gulp-clean-css'),
order = require('gulp-order'),
flatten = require('gulp-flatten'),
merge = require('merge-stream'),
less = require('gulp-less'),
@dgpro
dgpro / xdebug_laravel_artisan.sh
Last active May 26, 2017 13:38
Xdebug Laravel's artisan commands in console on vagrant for PhpStorm
# How it works:
# Make sure you have xdebug installed and configured on your server
# Make sure PhpStorm is listening for PHP Debug connections
# Just add your breakpoints and run a command
# 10.0.2.2 is your guest ip (I guess)
# and the only place I could find it is when you run `vagrant ssh`
# it will be printed next to "Last login: <date> from 10.0.2.2"
# More info here http://stackoverflow.com/a/28856207/1479743
php -dxdebug.remote_autostart=on -dxdebug.remote_connect_back=off -dxdebug.remote_host=10.0.2.2 artisan <command>