Skip to content

Instantly share code, notes, and snippets.

View yoshikakbudto's full-sized avatar

Dmitry yoshikakbudto

  • Targem Games
  • Yekaterinburg city, Russia
View GitHub Profile
@yoshikakbudto
yoshikakbudto / simple_retry.sh
Last active April 10, 2021 17:45
bash function that progresive retries a command with support of "ok exit codes"
# $1 exit code
# $2 ok exit codes (comma separeted)
#
verify_exitcode(){
local j
for j in ${2//,/ };do
if [ $j -eq $1 ]; then
echo "[info] assume exit code $j as ok"
return 0
fi
@yoshikakbudto
yoshikakbudto / ver2num.py
Created March 18, 2021 07:43
convert version numbers into one number
#!/usr/bin/env python
"""
Convert version number of only digits into one number, ready for comparing.
"""
v1=(1,20,0,10)
v2=(1,20,1,0)
# length in bits of each version number.
# for example '8' allows to use version number with elements of a max 256: "256.256.256.256"
@yoshikakbudto
yoshikakbudto / json2xml.py
Last active April 16, 2020 19:17
python convert json to xml
def json2xml(json_obj):
"""Simple converter from json to xml
Kudos go to https://stackoverflow.com/questions/8988775/convert-json-to-xml-in-python.
"""
result_list = list()
json_obj_type = type(json_obj)
if json_obj_type is list:
@yoshikakbudto
yoshikakbudto / stdinToPopen.py
Last active December 28, 2018 12:49
python feed STDIN to Popen process
#!/usr/bin/env python
from subprocess import Popen, PIPE
import shlex
items = ['i1', 'i2', 'i3']
cmd='xargs -rn1 -I% echo "run for %"'
p = Popen(shlex.split(cmd), stdout=PIPE, stdin=PIPE, stderr=PIPE)
# this will emulate the shell sequence: "echo 'i1 i2 i3'|tr ' ' '\n'|xargs ..."
@yoshikakbudto
yoshikakbudto / mongodb_collection_sizes.js
Last active September 14, 2018 09:06 — forked from joeyAghion/mongodb_collection_sizes.js
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
var mgo = new Mongo()
function getReadableFileSizeString(fileSizeInBytes) {
var i = -1;
var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
do {
fileSizeInBytes = fileSizeInBytes / 1024;
i++;
} while (fileSizeInBytes > 1024);