XML-lister

XML lister is a small program that lists the elements, values and attributes of XML files. <?xml version="1.0"?> <layout> <default> <reference name="root"> <reference name="content"> <block name="product.info"> <action method="test"> <param>test</param> <param2>test2</param2> </action> </block> </reference> </reference> </default> </layout> XML lister will print the following list: layout layout/default layout/default/reference layout/default/reference@name root layout/default/reference/reference layout/default/reference/reference@name content layout/default/reference/reference/block layout/default/reference/reference/block@name product.info layout/default/reference/reference/block/action layout/default/reference/reference/block/action@method test layout/default/reference/reference/block/action/param test layout/default/reference/reference/block/action layout/default/reference/reference/block/action/param2 test2 layout/default/reference/reference/block/action layout/default/reference/reference/block layout/default/reference/reference layout/default/reference layout/default layout A few days ago I wanted to find out if there are places in Magento layout XML files where reference elements are used inside other reference elements....

March 31, 2016

Rewrite XML with xmlstarlet

XML Starlet is a program that makes transforming XML documents really simple. The command that you need to transform an XML document is the following. 1 xmlstarlet tr [<options>] <xsl-file> {-p|-s <name>=<value>} [ <xml-file-or-uri> ... ] The XSL file that transforms a document to itself is this. It copies all elements, attributes and texts. We can extend this file to remove, add, or transform elements. 1 2 3 4 5 6 7 8 9 <?...

March 16, 2016

Removed Analytics

I just removed Analytics from my website. It’s not important for me. I don’t have the time to look at it.

November 6, 2014

Sorting DNS records

I don’t update my DNS records often, but when I do I like these records sorted. A DNS record consists of the following fields: domain name, type and prio (for some types). I use these fields to determine the order of the records. That is also the order in which these fields should be ordered. The first insight I had about sorting domains was that the domain names consist of parts separated by a period....

September 4, 2014

Rotate one to the left

Last week I wrote a small function in Perl that rotates and array to left. The function takes the item from the front and appends it to the back. # precondition: @list >= 1; sub rotate_left_by_one { my $ar = shift; my $item = shift @$ar; push @$ar, $item; return; } After calling this function as many times as the length of the array, it leaves the items in the same order they started in....

August 18, 2014

Low level code

Google released the PDF code of Chrome just a few days. I took a look at it. This file (core/src/fpdfdoc/doc_vt.cpp) is an example of how the code looks. Sometime later it dawned on me that this code is built out of only low level pieces. There are almost no algorithms extracted to functions. An example would binary search. There are five copies of binary search hidden in just that file. No wonder this file is 1864 lines of code....

May 23, 2014

StrictWeakOrdering

I always forget what strict weak ordering means, but it’s quite simple, actually. My explanation is based on the Programming Conversation of last week and I hope this will help me remember the next time I hear about this. Let’s start with ordering. A relation is an ordering if it is transitive. ordering --> for all a, b, c: r(a, b) and r(b, c) => r(a, c) And now strict....

May 13, 2014

Broken interface of Math.min

In an article about creating a column layout I found the following two lines of code: var min = Array.min(blocks); var index = $.inArray(min, blocks); This first finds the minimum value in blocks and then the index of that value. This combination of lines is very strange. Array.min already knows the index of the minimum element and throws it away. Then the programmer needs to find the index again with a linear search....

April 29, 2014

Stability in column layout

I was reading the notes on programming PDF and found a discussion about writing min and max functions for multiple arguments. I didn’t what to use this for. Also there was a discussion about stability. Stability is when you leave elements in the same position when they’re the same. This seems to be about sorting. At the same I was implementing a Pinterest like column layout. I already had a working version....

April 29, 2014

Renewed interest in C++

In the previous post I showed a playlist of presentations by Alexander Stepanov, the creator of STL. In these videos he talks about algorithms and data structures (written in C++). This principled explanation of programming makes a lot of sense to me. And has me take a renewed look at C++.

April 22, 2014