Monthly Archives: January 2014

Retrieving multi-line sequences from text files

Had some free time and had a need to parse out a number if similar (but not the same) blocks from a log file. There are tools for that – it could be done with a mixture of grep, sed, bash and some arcane magic – but I’m afraid to find the right toolset, learn required keys for each and experiment with their values and combination would take me longer than to just write me a tool. And it was another opportunity to write a few lines in Python, which I don’t do often enough. And I do love text processing.

So I made me a neat little tool that essentially does one simple thing – starts printing the input stream when some (start) trigger is found there, and stops when another (end) occurs. There are some additions – like, print some lines before/after the block, print couns, unique blocks only etc. – but those are glitter, mostly.

Available in a BitBucket repository.

WordPress plugins etc.

I’ve been (quite subconsciously) using WordPress for quite some time now, mostly for my alcoholic beverages blog (it’s in Russian, sorry). Subconsciously because it was the first option GoDaddy offered me a “automated install” blogging platform – and also because I’ve heard the name a number of moons back, so it should’ve been well documented and supported at that point. It’s on PHP, but who cares. I’ve spent years writing PHP code.

So I had this problem: my articles all have a rating (I use Author Post Ratings plugin by Philip Newcomer), but it’s not possible to see all the high-rated articles, nor it is possible to order articles by rating within a category – and this feature made a lot of sense, because when you go to a site with a bunch of reviews, you usually look for the best stuff within some category.

So I gave it a thought and just went and added required functionality – now it’s there on bitbucket,¬†https://bitbucket.org/hydralien/author-post-ratings/src

Turned out writing WordPress plugins is a no-brainer if you need something simple (I started with a post-by-rating list) – you just add directory, create a PHP file with a proper header, and you’re done. Well, after you add your functionality, that is. WordPress has some¬†lovely documentation on that.

It gets trickier if you need to change “internal behavior” – such as category sort order – but documentation helps there as well, there are filter hooks for that.

I guess this is worth a slogan – something like “Better drinking with no hassle” or “Drinking better just got easier”. Or whatever.