Bookmarklet to show anchors

Recently found this bookmarklet that visualizes anchor tags in a web page (elements with an ID and anchor tags with a name). Unfortunately Chrome doesn’t like it because it loads jQuery. It also contains a base64 image of anchor. Nowadays you don’t need jQuery for simple tasks and there’s probably an emoji that suits your needs. So, there you go, a simpler bookmarklet:

javascript:Array.prototype.filter.call(document.querySelectorAll('[id],a'),function(e){if(e.nodeName!='A'||e.getAttribute('name')){e.insertAdjacentHTML('beforebegin','<a href="#'+(e.id?e.id:'')+(e.name?e.name:'')+'">&'+'#x2693;</a>')}});

Updated: added an anchor tag around the anchor emoji with the actual bookmark.

Advertisements

The Guitar and the Piano

Sometime ago I read this article about the future of Lisp. Even if you’re not interested in Lisp there is an interesting explanation of two design philosophies the author calls The Right Thing and Worse is Better. His description is rather long, so I’ll grossly misinterpret it by summarizing it as: any tool used by developers (a programming language, OS, framework, library or anything with an API) at some point needs to choose between keeping the tool simple or moving the complexity into the tool. In general, a simpler tool makes it easier to understand what’s going on “under the hood” and thus offers more control. In contrast, moving the complexity into the tool makes its usage simpler.

A good analogy I think is a guitar versus a piano. A guitar is arguably the simpler instrument. It has few moving parts and it’s reasonably portable. By contrast a piano has most of it’s mechanics “under the hood” and you certainly wouldn’t take it with you on a camping trip. On the other hand striking chords on a guitar is a fairly complicated affair that is difficult to grasp by a beginner, both literally and figuratively. On a piano it’s still a cinch, but at least the notes are laid out right next to each other. Also with a piano (and enough practice) it is possible to play different things with either hand. With a guitar this only works with specific chords and often requires sacrificing notes.

Now I suck playing either instrument so don’t take this too far, but I hope you see the analogy. In any case, there certainly isn’t a “best” instrument, only what’s best in a given situation.

Let’s consider an extreme case, C versus Haskell. C is clearly the simple, “guitar” type tool favoring precise control needed in systems programming. In contrast, Haskell is the expressive “piano” type tool for implementing complicated algorithms.

A more subtle case is systemd. Because it handles dependencies between daemons “under the hood” its configuration is simpler than other init systems. Whether this follows the Unix philosophy (“Do one thing and do it well”) is, in my opinion, a matter of scope; If handling dependencies is what you want your init system to dosystemd certainly does it well. But Unix traditionally favors simpler tools and many long-time users don’t like giving up the more precise control these offer.

I’m sure you can think of more examples, it’s a recurring theme. The key takeaway is that there’s no clear winner, it depends on personal preference and the specific situation.

Let’s hope more people will realize that before starting a flame war.

KB2995388 breaks VMWare Player

Update: this is fixed in VMWare Player 6.04.

After installing update KB2995388 my VMWare Player images refused to start. Only after reducing the required virtual memory to 2 GB or less they would run. Reinstalling Player didn’t work. Luckily after removing the update things returned to normal. The reader be warned…

Running ActiveMQ as non-root

Running ActiveMQ as non-root with a handy script and a small tweak in conf/log4j.properties: replace log4j.appender.logfile.file=${activemq.base}/data/activemq.log with log4j.appender.logfile.file=${activemq.data}/activemq.log to prevent ActiveMQ from putting the log in the installation folder.

Though I suppose you could also create a new broker instance.

What is Node.js?

It took me some time to get my head around the peculiarities of Node.js so here’s my take on explaining it.

What is Node?

Node(.js) is a program that allows you to run programs written in JavaScript.

But I heard it is a Web Server?

Well a Web Server is a program; you can write one in JavaScript with Node.

Why is it so popular?

Well web developers like to create tools in JavaScript because they are using that language already for programming the browser. For that reason it is also a compelling web server. Some frameworks even allow you to run the same code on the server and the browser. But Node has another advantage.

How come Node beats established web servers?

Node uses a novel approach at dealing with concurrency, that is all the requests and responses a web server needs to process.

So how does Node deal with concurrency?

Well it’s like comparing a large crossing to a roundabout. If a crossing is complicated and busy it needs traffic lights to start and stop the flows that would otherwise collide. With a roundabout however, all flows merge into a large loop and traffic ramps off at the various exits.

Another analogy is a restaurant serving several customers. To deal with all the cooking involved you could:

  • Have multiple kitchens. This is like multiple processes.
  • Have several cooks working in the same kitchen. This is like multithreading.
  • Split the work into small steps that complete quickly. When there is waiting involved (for the oven to finish or water to boil) move on to the next task and continue when the waiting is over.

Traditional web servers use multiple processes and multithreading. The third option is obvious for cooking but not for web servers.

The main downside of each method is:

  • Multiple processes requires a lot of memory and switching and communication between processes requires considerable CPU time.
  • Multithreading is hard when resources are shared. Also each thread requires memory and switching requires CPU time.
  • Splitting programs into small steps requires a language to split code into small parts while still being able to see the flow of tasks.

To be fair Node is not the first web server doing things this way, but it sure made it popular.

Why JavaScript?

Well, besides being able to use the same language in the browser JavaScript has two advantages:

  • It has lambdas, useful for splitting programs into small parts.
  • It has nothing else for handling concurrency, so there’s less confusion.

“Insufficient Storage” on Samsung Galaxy S II (I-9100)

My wife’s phone (Samsung Galaxy S2 I-9100, upgraded to Android 4.1.2) recently refused to update any installed apps with the error ‘Insufficient Storage’, even though the phone clearly had enough internal storage left to install at least some apps.

After surfing the web I found 2 solutions that worked:

  1. In the dialer type *#9900#. You get some techie menu, then choose the second menu option Delete dumpstate/logcat.
  2. Shut down the phone then start it up by holding the Volumne Up, Power and Home buttons. You boot into the recovery menu. Then choose the second last option Wipe the cache partition. Then restart the phone normally.

This solved the problem, now all apps update without any problems.

Navigation Bar issues between iOS 6 and iOS 7

A major difference between iOS 6 and 7 is that in iOS 7 the navigation bar is translucent by default and stuff appears underneath it instead of being shifted down.

Normally this is fixed by making the navigation bar opaque, but this doesn’t always work. An additional solution is described here, and translated to Xamarin it is:

using MonoTouch.ObjCRuntime;

...

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
    {
        EdgesForExtendedLayout = UIRectEdge.None;
    }
...
}