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 / SCC-with-Unicode
Created August 9, 2016 15:17
An example of SCC closed captions with Unicode special symbols
Scenarist_SCC V1.0
00:00:00;00 94ae 94ae 9420 9420 94d0 94d0 9137 2049 20e3 616e 20f4 e5ec ec20 6279 20f4 6861 f420 f7ef f2f2 e9e5 6480 9470 9470 ecef ef6b 2079 ef75 2067 eff4 20e3 ef6d e96e 6720 ef6e 2079 efa7 20e6 61e3 e580
00:00:01;11 942c 942c
00:00:51;01 942f 942f
00:00:51;05 94ae 94ae 9420 9420 94d0 94d0 2020 2080 9137 20c2 e5e5 6e20 f7ef f2f2 79e9 6e67 2061 62ef 75f4 9470 9470 2020 2080 6def 6ee5 7920 6def 6d6d 6120 4920 e361 6e20 f2e5 70ec 61e3 e580
@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'),