Skip to content

Instantly share code, notes, and snippets.

View samir64's full-sized avatar

Samir samir64

View GitHub Profile
@samir64
samir64 / script.sh
Created June 13, 2024 09:02
Restart a docker container by a part of its name when in last 200 line of its log has more than 150 times of specific message
#!/usr/bin/bash
if [ -z $1 ]; then
echo "Container name is empty"
exit -1
fi
if [ -z "$2" ]; then
echo "Message is empty"
exit -1
@samir64
samir64 / Behavior.js
Last active March 1, 2019 22:42
Javascript (ES5) Class
'use strict';
/**
* @param {string} behavior
*/
Behavior = Class.extend({
init: function (behavior) {
this.super();
Object.defineProperty(this, "Behavior:" + behavior, {
@samir64
samir64 / replace-regexp.sh
Last active May 6, 2018 11:16
Replace substrings by another strings and return value to first parameter of passed arguments in bash script
function replace_regexp() {
local result=$1
local text=$2
shift
shift
while [[ $# -gt 0 ]]; do
text=$(echo $text | sed -E "s/$1/$2/g")
shift
shift
done
@samir64
samir64 / logger.php
Last active April 28, 2018 16:20
PHP logger function
<?php
//NOTE: For use the Logger function copy these two lines to your code and fill $LOGGER_VARIABLES array by your variables
/*
$LOGGER_VARIABLES = [];
LOGGER(__FILE__, __METHOD__, __LINE__, function () use ($LOGGER_VARIABLES) {var_dump($LOGGER_VARIABLES);});
*/
//NOTE: PHP error reporter
//error_reporting(E_ALL);
error_reporting(E_ALL ^ E_STRICT);
@samir64
samir64 / import.php
Created April 28, 2018 15:29
A simple function to import file instead require or include
<?php
function import($caller_file, $package, $script) {
require_once(realpath(dirname($caller_file) . "/" . $package . "/" . $script));
}
@samir64
samir64 / counter1.py
Last active May 6, 2018 18:29
Python and Bash script progress counter sample
import sys
import time
for i in range(0, 101):
sys.stdout.write("Progress: %d%% \r" % i)
sys.stdout.flush()
time.sleep(0.05)
pass
sys.stdout.write("\r\n")