Zum Hauptinhalt springen
Chris’ wirre Gedankenwelt
  1. Tags/

Coding

Tell me about the why

Today I came around this piece of code and struggled at the comment.

urlbase64() {
    # urlbase64: base64 encoded string with '+' replaced with '-' and '/' replaced with '_'
    openssl base64 -e | anti_newline | sed -r 's/=*$//g' | tr '+/' '-_'
}

Of cource, this comment is not entirely useless, since it tells me what the function is going to do.

But the important information is missing: The why. Tell me about why you are doing it. Maybe also why you are doing it this was. Most of the time, it is much more difficult for the reader to figure out the why. The what and the how are often obvious.

Monkey patch a puppet provider

I just wanted to monkey patch the puppet package provider for gentoo portage.

But why?

# puppet resource package

Only shows packages installed by puppet, but not packages installed by hand. The apt/dpkg- and yum/rpm-provider list all packages.

It was not enough to place a lib/puppet/provider/package/portage.rb. In all my tests, the original behavior was kept. I only want to replace one function.

But how?

When registering new type or providers, etc, puppet is doing a bunch of magick in the background. So first, I have to figure out the name of the automagically created class.

redis subscribe to key

Redis has a buildin pubsub mechanism, but by default it is not possible to listen on specific keys. Redis 2.8 intruduced Keyspace Notifications , to which you can subscribe.

First of all. This feature is disabled by default, so we need to enable it

$ redis-cli config set notify-keyspace-events KAE

This little python-script listens on keyspace-Events containing stash:silence/*

#!/usr/bin/env python

import redis

r = redis.StrictRedis()

pubsub = r.pubsub()
pubsub.psubscribe('__keyspace@*:stash:silence/*')
for msg in pubsub.listen():
    print(msg)

Results to:

Python Links

Sehr ohne Context, ein paar Python Links, die ich in den letzten Tagen und Wochen interessant fand.

http://www.jeffknupp.com/blog/2014/06/18/improve-your-python-python-classes-and-object-oriented-programming/

pypy3 mit python 3.2.5 rausgekommen. http://morepypy.blogspot.de/2014/06/pypy3-231-fulcrum.html

Hilfsbibliothek um python 2 & 3 im selben Code zu unterstützen: https://pypi.python.org/pypi/six

Würde Python 2.8 bei der Portiereung auf 3 helfen? https://regebro.wordpress.com/2014/06/03/would-a-python-2-8-help-you-port-to-python-3/

Ein bisschen mobiler

CSS media queries, galaxy s3, cyanogenmod 10.2 und viel gelernt.