Skip to content

Instantly share code, notes, and snippets.

💭
Learning python and golang

Ilya Sheershoff sheershoff

View GitHub Profile
@sheershoff
sheershoff / docker-swarm-find-container
Created Nov 15, 2018
docker swarm find hostname by container id or hostname using two methods
View docker-swarm-find-container
#!/bin/bash
#
# Default settings block, change here if you need or put other defaults to your .bashrc
#
DSFC_USER="${DSFC_USER:-root}" # defaults to root
DSFC_HOSTS_GREP="${DSFC_HOSTS_GREP:-"swarm-"}" # what to grep in /etc/hosts
DSFC_HOSTS_LIST="${DSFC_HOSTS_LIST:-`(cat /etc/hosts | grep ${DSFC_HOSTS_GREP} | cut -f1 | xargs -L1 echo | uniq)`}" # change the default inside backticks to your way to get hosts list
DSFC_METHOD_SSH="${DSFC_METHOD_SSH:-1}" # whether to use the ssh and docker ps method
@sheershoff
sheershoff / pdftk
Last active Nov 8, 2018
pdftk CLI for ubuntu 18.04 or later in docker replacement
View pdftk
#!/bin/bash
# Build or use cached image and tag with "local/local/ubuntu_pdftk", suppress output
# to maintain compatibility in case you are parsing the pdftk output.
# It will build the image if it's absent or use the cached one.
echo "FROM ubuntu:16.04
RUN apt-get update && \
apt-get install -y pdftk && \
rm -rf /var/lib/apt/lists/*" | docker build -t local/local/ubuntu_pdftk - 2>&1 > /dev/null
@sheershoff
sheershoff / dcsl
Last active May 20, 2018
Docker-compose logs sorted by time
View dcsl
#!/bin/bash
usage="Input piped docker-compose logs -t, or a file created from this command, to show logs lines sorted by time.\n\n Usage:\n\n $(basename "$0") [-h|--help] - this message\n $(basename "$0") - runs default docker-compose logs -t and sorts'em\n docker-compose logs -t|$(basename "$0") - pipe logs to this command\n $(basename "$0") my-compose.log - or choose file with logs to display\n\n"
[ $# -ge 1 -a -f "$1" ] && input="$1" || input="-"
case "$1" in
-h|--help) printf "$usage"
exit
;;
esac
if [ -t 0 ]; then
docker-compose logs -t|sort -t "|" -k +2d
@sheershoff
sheershoff / Migration.php
Created Nov 23, 2015
yii2 sqlite migration class for dropColumn, renameColumn, alterColumn. Also silently blocks addForeignKey.
View Migration.php
<?php
/**
* Created by IntelliJ IDEA.
* User: sheershoff
* Date: 11/23/15
* Time: 9:59 PM
*/
namespace generic\namespace; // use whatever you need to include in your migrations
use Yii;
@sheershoff
sheershoff / kl_to_1c_to_kontur_elba_format.php
Created Feb 9, 2015
kl_to_1c format reader, with exporter to elba kontur format
View kl_to_1c_to_kontur_elba_format.php
<?php
$i = 0;
$in = [];
$state['inDocSection'] = false;
function cmpget($l,$key){
if(strncmp($l,$key,strlen($key))!==false){
$v = substr($l,strlen($key));
@sheershoff
sheershoff / php-multidimensional-array-search-return-keys.php
Last active Oct 26, 2017
php recursive search multidimensional array for value and return key sequences
View php-multidimensional-array-search-return-keys.php
<?php
namespace common\helpers;
class ArrayHelper extends \yii\helpers\ArrayHelper
{
public static function multiSearch($needle, $haystack, $options = ['strict' => false, 'yiiFormat' => false])
{
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator([$haystack]));
// parent array is skipped in subiterators, so we wrap the argument in one more array
$results = [];
You can’t perform that action at this time.