Skip to content

Instantly share code, notes, and snippets.

View sheershoff's full-sized avatar
💭
Learning python and golang

Ilya Sheershoff sheershoff

💭
Learning python and golang
View GitHub Profile
@sheershoff
sheershoff / dcsl
Last active June 14, 2023 18:05
Docker-compose logs sorted by time
#!/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 November 23, 2015 16:01
yii2 sqlite migration class for dropColumn, renameColumn, alterColumn. Also silently blocks addForeignKey.
<?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 / pdftk
Last active December 12, 2022 13:59
pdftk CLI for ubuntu 18.04 or later in docker replacement
#!/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 / php-multidimensional-array-search-return-keys.php
Last active August 5, 2019 10:49
php recursive search multidimensional array for value and return key sequences
<?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 = [];
@sheershoff
sheershoff / docker-swarm-find-container
Created November 15, 2018 20:24
docker swarm find hostname by container id or hostname using two methods
#!/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 / kl_to_1c_to_kontur_elba_format.php
Created February 9, 2015 11:12
kl_to_1c format reader, with exporter to elba kontur format
<?php
$i = 0;
$in = [];
$state['inDocSection'] = false;
function cmpget($l,$key){
if(strncmp($l,$key,strlen($key))!==false){
$v = substr($l,strlen($key));