Sunday, March 11, 2018

python: Django-like testrunner

Django-like testrunner for non-django projects:
#!/usr/bin/env python

import argparse
import collections
import unittest
import sys

def main():
    parser = argparse.ArgumentParser(description='Django-like testrunner')
    parser.add_argument('specific_test', metavar='', type=str, nargs='?', help='Specifc test')
    parser.add_argument("--failfast", action="store_true")
    parser.add_argument("--verbosity", type=int, default=1)

    args = parser.parse_args()

    loader = unittest.TestLoader()
    all_tests ='.', top_level_dir="./")
    suite = unittest.TestSuite()

    if args.specific_test:

        def walk_tests(tests):
            if isinstance(tests, collections.Iterable):
                for item in tests:
            elif not str(tests).startswith("test"):
                sys.exit("Error in file %s" % tests)


    unittest.TextTestRunner(verbosity=args.verbosity, failfast=args.failfast).run(suite)

if __name__ == "__main__":

fedora: SSL certificate viewer

GUI to view certificate:
gcr-viewer cert.pem

linux: List all IP addresses in a network

To list ip addresses of all connected to the network devices, use this command:
nmap -sn

linux: CPU benchmark

$ sysbench cpu run --time=5
sysbench 1.0.9 (using system LuaJIT 2.1.0-beta3)

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time

Prime numbers limit: 10000

Initializing worker threads...

Threads started!

CPU speed:
    events per second:  1157.88

General statistics:
    total time:                          5.0008s
    total number of events:              5792

Latency (ms):
         min:                                  0.80
         avg:                                  0.86
         max:                                  3.74
         95th percentile:                      1.06
         sum:                               4998.26

Threads fairness:
    events (avg/stddev):           5792.0000/0.00
    execution time (avg/stddev):   4.9983/0.00

bash: How to check what hides behind an alias

To check what command is assigned to the alias use type command:
$ type gl
gl is aliased to `git log --oneline'

Thursday, November 16, 2017

fedora: Install flashplayer in Firefox

I have flashplayer installed on my system from the official Adobe repository, but Firefox for some reason does not have flash plugin installed. You can check if your browser supports flash by navigating to this url

To make Firefox aware of flashplugin, try to create a symlink here:

cd && ln -s /usr/lib64/flash-plugin/ .

Thursday, November 2, 2017

Monitor process with top

One liner to monitor a process with the name /wshub:
top -p "$(pgrep -f /wshub)"

Tuesday, October 31, 2017

Run command as a different user

Command runuser allows to run a command as a different user. You must be root to be able to run that command:
sudo runuser -l vagrant -c "GH=1 env"

Friday, October 13, 2017

Monitor cpu and memory usage of the process

Print every second cpu and memory usage of the process:

watch -n 1 "ps -eo pid,pcpu,pmem,args | kazy -i xnotitle -e kazy"

Firefox Quantum: No titlebar

In "old" Firefox times I used to use HTitle extension. It removes useless titlebar in Firefox in GNOME 3. However, the extension was discontinued. Firefox starting version 56 does not support Legacy extension and new solution is needed.

I wrote a small application which hides titlebar of the maximized windows. xnotitle is written in Go. By default, every second it checks for a new window which contains "Mozilla Firefox" in the title and applies special style to disable the title bar when the window is maximized.

xnotitle can be used to hide title bar for any application. Specify window title to hide with -name argument. You can also adjust how often xnotitle is going to check for new windows.

To start using application, clone the repository and build the project:

git clone
make build
You should have go installed.

After xnotitle is compiled, start it automatically with the system by creating ~/.config/autostart/xnotitle.desktop file with the following content:

[Desktop Entry]
Comment=xnotitle hides title bar of the specified windows

I recommend also installing Close Window Button extension to add Close window button (as titlebar is gone and all window control buttons too)

Monday, July 31, 2017

Use mitmproxy with GNOME Web (Epiphany)

To use mitmproxy with Epiphany you need to install CA certificate from mitmproxy. To do that, start mitmproxy and navigate to Download *.pem certificate (available under Other link). Install mitmproxy certificate with command:
sudo trust anchor mitmproxy-ca-cert.pem 
With this command you can also install any custom certificate to use in Epiphany.

Tuesday, July 18, 2017

Overwrite response body with mitmproxy 2

Run python script with mitmproxy:
mitmproxy --ignore -s
Script example:
from mitmproxy.script import concurrent

OLD = """var totalExpGems=0;"""
NEW = """var totalExpGems=0;debugger;"""

def response(flow):
    if "gem_finder" in flow.request.path:
        flow.response.headers["XX"] = "PATCHED"
        body = flow.response.content.decode("utf-8")
        if OLD in body:
            flow.response.content = body.replace(OLD, NEW).encode("utf-8")
            flow.response.headers["XXX"] = "PATCHED"

Monday, May 8, 2017

Get size of the subfolders

Use this command to print size of the subfolders:
du -sh *
If you want to exclude Permission denied errors, for example:
du -sh * 2>/dev/null

Monday, March 27, 2017