Skip to content

Instantly share code, notes, and snippets.

https://git-scm.com/docs/git-remote
git remote prune --dry-run origin
git remote update origin --prune
# get all removed branches on server side
git branch -vv | grep -Po '\s(feature\S+)(?=.*\s+gone\])'
# so you can remove all "gone" branches:
git branch -D $(b -vv | grep -Po '\s(feature\S+)(?=.*\s+gone\])')
@andreyserdjuk
andreyserdjuk / docker_static_ip.sh
Last active April 9, 2022 19:15
docker static ip
# in case of conflict with local nginx:
# make sure in all *.confs (
# also in default and example to avoid error like
# 'nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)'
# )
# set for instance "listen 127.0.0.1:80" instead of "listen *:80"
# docker & network settings
DOCKER_IMAGE_NAME="maxexcloo/nginx-php" # build of nginx-php - for example
DOCKER_CONTAINERS_NAME="nginx_bridged" # our container's name
@andreyserdjuk
andreyserdjuk / flatten_exceptions.php
Created January 17, 2022 13:21
flatten parent exceptions
<?php
function a() {
throw new \LogicException('bad logic in A');
}
function b() {
try {
a();
} catch (\LogicException $e) {
@andreyserdjuk
andreyserdjuk / xdebug_toggle.sh
Last active May 22, 2019 19:24
xdebug toggle script
unamestr=`uname`
PHP_INI_PATH=$(php --ini | egrep -o '\S+php.ini$')
if [ -z $(php -m | grep xdebug) ]; then
if [[ "$unamestr" == 'Linux' ]]; then
sudo sed -i "s/^;zend_extension/zend_extension/" $PHP_INI_PATH
elif [[ "$unamestr" == 'Darwin' ]]; then
sudo sed -i "" "s/^;zend_extension/zend_extension/" $PHP_INI_PATH
fi
echo 'Xdebug enabled'
@andreyserdjuk
andreyserdjuk / detect_unicode.php
Created July 28, 2017 10:38
is unicode string?
<?php
$message = 'test';
if ('ASCII' !== mb_detect_encoding($message, 'ASCII', true)) {
echo 'Unicode' . PHP_EOL;
} else {
echo 'ASCII' . PHP_EOL;
}
@andreyserdjuk
andreyserdjuk / determine_csv_delimiter.php
Last active July 26, 2017 10:59
determine csv delimiter php
<?php
/**
* Determine csv delimiter
*
* @param resource $fileHandle - handle of csv file
* @return string - correct delimiter of csv file
*/
function determineCsvDelimiter($fileHandle)
{
@andreyserdjuk
andreyserdjuk / cheerio_example.js
Created November 8, 2016 19:36
cheerio parser example
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const fs = require('fs');
let url = "http://loveread.ec/read_book.php?id=56443&p=";
let requests = [];
let startTime = new Date().getTime();
for (let counter = 1; counter < 36; ++counter) {
requests.push(
@andreyserdjuk
andreyserdjuk / pcntl_signal_example.php
Created August 16, 2016 20:49
pcntl_signal() handler usage example
<?php
declare(ticks = 1);
pcntl_signal(SIGTERM, 'signalHandler'); // Termination ('kill' was called)
pcntl_signal(SIGHUP, 'signalHandler'); // Terminal log-out
pcntl_signal(SIGINT, 'signalHandler'); // Interrupted (Ctrl-C is pressed)
$seconds = 0;
$total = 10;
@andreyserdjuk
andreyserdjuk / prepare-commit-msg
Last active August 16, 2016 06:43
change commit message on branch example "feature/SPRINT-123" to message: "#SPRINT-123: commit message"
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
# changes commit message on branch example "feature/SPRINT-123" to message: "#SPRINT-123: commit message"
#
# INSTALLATION:
# - copy to .git/hooks/prepare-commit-msg
# - run chmod 555 .git/hooks/prepare-commit-msg
#
NAME=$(git branch | grep '*' | grep -Po '\w+-\d+' | sed -r 's/(.*)/#\1/')
@andreyserdjuk
andreyserdjuk / docker-compose.yml
Created January 2, 2016 20:45
docker-compose example
percona2:
container_name: percona-compose
image: percona:latest
environment:
- MYSQL_ROOT_PASSWORD=12345
php53:
container_name: php53-compose
image: markfletcher/php5.3-zend
links: