Skip to content

Instantly share code, notes, and snippets.

View lyuboraykov's full-sized avatar

Lyubomir Raykov lyuboraykov

View GitHub Profile
@lyuboraykov
lyuboraykov / loading.sh
Created September 1, 2014 08:49
Loading console animation.
#!/usr/bin/env bash
LOADING_SYMBOLS=("\\" "|" "/" "-")
INDEX=0
while true; do
INDEX=$(bc <<< "($INDEX + 1)%4")
echo -ne "${LOADING_SYMBOLS[$INDEX]} \033[0K\r"
done
@lyuboraykov
lyuboraykov / arguments.sh
Last active August 29, 2015 14:05
Parse long command line arguments in Bash
#!/usr/bin/env bash
# Console-line parameter parsing script.
# Specify options in the OPTS variable in the following format:
# whitespace sepparated values
# OPTS="--<argument_name> --<argument_with_value>= --!<mandatory_argument>="
# Then it creates variables in the format: OPTS_<ARGUMENT_NAME_IN_CAPS>
# If the argument doesn't need value to be provided assings 0 or 1.
# If the argument needs value but none is provided a 0 is assigned
@lyuboraykov
lyuboraykov / prettylogger.py
Created August 26, 2014 14:43
Log python calls in a tree-format
import sys
from datetime import datetime, date
class PrettyLogger(object):
"""
Class wrapper for a system trace function. That makes
human readable stack trace logs.
"""
def __init__(self, logfile=sys.stdout, max_indent=0):
"""
@lyuboraykov
lyuboraykov / downloadsongs.py
Created August 25, 2014 19:07
Download songs from youtube
# -*- coding: utf-8 -*-
import pafy
import requests
from multiprocessing import Pool
import pyglet
import os
import sys
def get_url_from_name(name):
words = name.split()
@lyuboraykov
lyuboraykov / try-catch-copy.sh
Created August 21, 2014 07:53
Try-catch file copying in bash
#!/usr/bin/env bash
{
#try block
cp non/existing/file non/existing/folder
} || {
#catch block
if [ $? != 0 ]; then
echo "File copying failed."
fi
@lyuboraykov
lyuboraykov / printjenkins.groovy
Last active February 8, 2024 10:24
Print to console in Jenkins Groovy system script
def out
def config = new HashMap()
def bindings = getBinding()
config.putAll(bindings.getVariables())
out = config['out']
out.println "Printed do Jenkins console."
@lyuboraykov
lyuboraykov / piping.groovy
Created August 8, 2014 11:19
Execute shell command with piping in groovy
def command = 'ls | grep foo'
def output = ['bash', '-c', command].execute().in.text
@lyuboraykov
lyuboraykov / retry.groovy
Created August 7, 2014 13:18
Retryable logic in groovy
def retry(lambda, retries) {
for (def i = 0; i < retries; i++) {
try {
//better replace with logger
// println "Retrying: ${i + 1} of $retries"
lambda()
break
} catch (e) {
if (i == retries - 1) {
throw new Exception('Retrying failed', e)