Articles tagged Python

  1. Coding Python in Neovim with IPython as a REPL

    Most of the time at work I am currently doing machine learning / data science using the Python ecosystem. My editor of choice for working in Python has become Neovim, which really works well for autocompletion and linting based on Neomake, UltiSnips, deoplete and deoplete-jedi. However, one thing I have been missing was a tight integration with the IPython / Jupyter Console REPL in order to quickly experiment with new code fragments in a fashion like SLIME for Emacs: simply select a few lines of code and send them to IPython using a command / binding. Finally, I have found something that works well, which I will explain here.

    Read more

  2. autosuspend: Automatically Suspending a Server on Inactivity

    A few months ago I sold my existing basic Synology NAS and built my own one based on a power-efficient Intel CPU inside a mini ITX system with a usual Linux as the operating system. This provided me with a lot more flexibility and e.g. possibilities to encrypt my data properly. One thing I needed for this custom solution was a daemon to suspend the system in case of inactivity to further reduce the power consumption. I found a few existing scripts online, started using one of them, but soon had to modify it deeply until it was general enough to suit my needs. Today, I finally took the time to clean up the last issues in the code base and the autosuspend project is now available on Github.

    Read more

  3. Plotting the Separating Hyperplane of an SVM in 3D with Matplotlib

    I have been struggling how to plot the separating hyperplane of an SVM (a One-class SVM in my case) in a 3D space using matplotlib. There was no apparent way how to convert the decision function output into something that one of the 3D plotting functions could deal with. Fortunately I found a solution which I am going to share in case someone wants to do the same.

    Read more

  4. A Python logging broadcast handler

    I have implemented a handler for the Python logging system called broadcast-logging which sends out the log messages via UDP broadcasts. This might be useful in case you want to sporadically listen to certain log messages, e.g. from a server, without setting up a special service for this purpose. Since broadcasts are sent via UDP and no explicit connections are set up, this might also be useful in case you want to debug TCP-connection-related issues while preventing artificial connections for the debugging session.

    Read more

  5. matplotlib: Interactively zooming to a subplot

    I am using matplotlib a lot for my data analysis tasks and most things work as I expect them to do. One thing that I was missing so far for interactive use was the ability to focus an individual subplot and temporarily let it fill the whole screen for deeper inspection of this plot. In case of multiple subplots, with the standard GUI elements you can zoom and move around inside each subplot (without changing their geometry), but not focus one of them individually. Therefore I came up with the following solution:

    Read more

  6. pass-git-helper: Integrating the pass password manager with git

    I am using password managers since a long time to maintain secure and individual password for different online services. One thing that always bothered me was the missing integration of these password managers with different applications. I started my journey with password managers using KeePassX but recently switched to pass (the standard unix password manager) due to the inherent command line nature and therefore much better integration and remote usage possibilities. Still, there was no easy way to integrate pass with Git (for those repositories where SSH key authentication is not possible) and until recently I still used kwallet as the backend for Git, with all the hassles of duplicated data. To improve on this situation I finally took some time and implemented an adapter between Git and pass: pass-git-helper.

    Read more

  7. Python Highlights

    Nice parsing differences between python versions:

    1
    2
    3
    4
    
    languitar@cinnabar:~$ python2 -c 'print("test", "42")'
    ('test', '42')
    languitar@cinnabar:~$ python3 -c 'print("test", "42")'
    test 42
    
    Read more
  8. How to set up a build system in C++, Python and Java

    I don't know why, but setting up the build system for a new software project and maintaining it seems to be something people are always afraid of. I've often heard people say "Eclipse does the job. It's just additional work." This usually leads to confusion and a lot of bulk and weird solutions several days later when the project starts to evolve...

    Read more
  9. Python logging configuration

    In case you ever wondered how to correctly configure the python logging system, e.g. from files and configuration server, this might be a useful link, which I hadn't see before: Logging Cookbook.

    Read more
  10. Difference between comparisons with == and is in Python

    In Python, two operators exist to perform equality comparisons: == and is. Often you can read instructions like "When comparing to None, always use is instead of ==", but the real reason is not explained. However, looking at the language expression specification section of the Python manual you can find the difference: "The operators is and is not

    Read more
  11. Evaluation of Default Arguments in Python

    Today I stumbled upon a very subtle problem with default arguments in python. I noticed that loading a python module already instantiated one of my classes even though I could not find an installation of this class. In the end it turned out to be a default argument for a function:

    1
    2
    
    def foo(arg=MyClass()):
        pass
    

    As I am currently programming...

    Read more
  12. PyGTK Segfault durch bereits geladenes GTK

    Seit zwei Wochen bastel ich mich jetzt schon um einen mir unerklärlichen Segfault beim Importieren von PyGTK herum. Heute hab ich dann endlich mal etwas Zeit gehabt das ganze genauer unter die Lupe zu nehmen. Das Modul in meinem Projekt, das die GUI-Funktionalität bereitstellt, enthält folgende Imports:

    1
    2
    3
    
    import pygtk
    pygtk.require('2.0')
    import
    Read more
  13. Style Guide für Python

    Style Guides für Java und C/C++ gibt es ja zu Hauf, für Python war mir aber bisher noch kein explizit aufgeschriebener aufgefallen - zumindest bis gestern: PEP 8 – Style Guide for Python

    Read more