Tracing Functions in Python

DateReadtime 2 minutes Tags

Sometimes I want to debug the inputs and outputs of function calls to visualize flow or to follow execution passively.

Rather than adding logging statements and littering them around the code, a single decorator can be crafted to show the life cycle of a function:

def trace_args(f):
    def wrapper …
more ...

Spinning down a Harddrive

DateTags

I wanted to spin down a hard drive before disconnecting. I have an external hard drive and even after I unmounted the drive the disks were still spinning.

Find the device label of the mounted drive:

$ lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda    253:0    0  20G …
more ...

List User Installed Packages

DateTags

I started thinking about doing a fresh linux install and was worried that I might not remember all the packages that I had manually installed. A quick search revealed a one-liner that compares the currently installed packages to the list of packages that were available initially to produce a nice …

more ...

Clean up Docker Instances

DateTags

Three useful commands to clean up docker if you run out of space

Clean up Containers

docker rm $(docker ps -a -q)

Clean up Images

docker rmi $(docker images | grep "^<none>" | awk '{print $3}')

Clean up Volumes

docker volume rm $(docker volume ls -qf dangling=true)
more ...

Configure pulseaudio output via command line

DateReadtime 1 minutes Tags

Changing the currently active audio output

List available audio devices

First, list all the available output devices like so:

pacmd list-cards

Or similarly:

pactl list cards

Card Index

Index of the card is found in the first couple lines:

$ pacmd list-cards
Welcome to PulseAudio! Use "help" for usage information.
>>> 1 …
more ...

Age of git tracked file II

DateReadtime 3 minutes Series Part 2 of Age of git tracked file Tags

Goal

Identify the last time an arbitrary line (let's say line 1) was changed for every file in the repository.

Step 1

Try and use blame to identify changes to the first line only:

$ git blame -L 1,1 -- README
^193d722 (Paul Schwendenman 2012-07-23 16:51:03 +0200 1) ======================

Grab …

more ...

Age of git tracked file

DateReadtime 5 minutes Series Part 1 of Age of git tracked file Tags

Goal

I use a password store named pass. Pass is a command line based manager that attempts to follow the Unix philosophy (roughly tools should do one thing and do it well.) I wanted to know when the last time I updated each password in my store, so that I …

more ...

Signing a multi page PDF

DateReadtime 2 minutes Tags

Background

Rather than printing a document, filling it out by hand and then scanning to so that you are able to return it electronically, use Gimp and ImageMagick to sign documents electronically.

Instructions

  1. First, make sure to have a png image with the signature on a transparent background.

  2. Next, open …

more ...

Pushing to pypi

DateReadtime 1 minutes Tags

Instructions

  1. Make setup.py in your project

    from setuptools import setup
    
    setup(name='project',
          version='1.0',
          description='thing do-er',
          author='Your Name',
          url='http://path.to.website',
          py_modules=[''],
          classifiers=['Environment :: Console',
                       'Intended Audience :: Developers',
                       'License :: OSI Approved :: MIT License',
                       'Programming Language :: Python :: 3.4',
                       'Operating System :: POSIX :: Linux',
                       'Topic …
more ...

Screenshot with mplayer

DateReadtime 1 minutes Tags

To take screenshots with mplayer, you need to first run mplayer with a special flag.

mplayer -vf screenshot movie001.mp4

Then once the movie is playing you can screen shot any frame by hitting the 's' key. mplayer will name the files starting with shot0001.png.

When I first tried …

more ...