Opera Mobile: Problems with position of dialog box

For the benefits of the hoards of readers here, the flood of master pieces continues.

I’m using Opera Mobile on Android. It works better than most other browsers in various ways. However, some sites have perhaps not tested with Opera Mobile?

For instance, go to http://www.disqus.com and click the login link in the upper right corner. A little dialog box pops up. (It’s not a window, but an html-element). Unfortunately, in Opera Mobile the dialog box is positioned so that its edge ends up outside of the edge of the “main screen”. The result in this case is that the actual Login button is not visible.

In essence, it does not seem to be possible to login to disqus.com using Opera Mobile.

I’ve noticed a similar problem with erroneously positioned html-elements on lastpass.com .

Crappy work-around: Use a bookmarklet that removes all stylesheet (CSS) on the page where such a problem occurs. Paste the following one-liner javascript into a bookmark (it’s a javascript “link”):


This is the bookmarklet named RemoveCSS from here: http://dorward.me.uk/software/disablecss/

By invoking/pressing the bookmarklet, the page will become ugly but functional — all elements will be visible on screen.

“Tjofjöjt i brallan”, as they say — it works!


Bookmarklet to clean Sparknotes for printing

Apparently I can’t buy the pdf-versions of the stuff on http://www.sparknotes.com, because I don’t have an american home address? That makes me grumpy. I guess I can just print out the articles myself, though that’s not very convenient.

But OK. To create a nice printable Sparknote page (without the mess, just the text), I use the following javascript code. It extracts the div element that has the className of studyGuideText and removes everything else (including all style sheets and an advert, floatingad).

javascript: ( function() {

var body = document.getElementsByTagName('body')[0];
var divs = body.getElementsByTagName('div');
var text = null;
for(var i=0; i<divs.length; i++){
	if(divs[i].className=='studyGuideText') {
		text = divs[i];
if (text == null) {
	alert('Did not find any text to extract (looking for divs of class studyGuideText)');
while (body.hasChildNodes()){


var els=document.getElementsByTagName('*');


The bookmarklet version — all in one line etc:


Tested only with Firefox (Gecko) and Epiphany (Webkit). (I would have liked to just publish it as a link, but WordPress mangles it to something incomprehensible.)

Order of mp3-tracks in Sansa Clip+

I use a Sansa Clip+ mp3-player for listening to audiobooks. It took me quite a while to understand how to get the player to play the tracks in the correct order, but I think the following should do it.

One has to edit the mp3-tags (metadata embedded into the mp3-files). I use EasyTAG to do this (which is available for Ubuntu, and probably many other Linux distributions and operating systems.)

Sansa Clip+ derives the play-order by looking at the “NUMBER” tag. EasyTAG displays this as the “Track”.

The NUMBER tag for each track has to have the same number of digits, so it usually has to be padded with leading zeros.

That is, tracks numbered like this will not work: 1, 2, 3, … 8, 9, 10, 11… because the Sansa player will sort tracks 10 and 11 before track 2 (which obviously will screw up the literary experience considerably).

Padding with leading zeros will solve this: 01, 02, 03, … 08, 09, 10, 11…

In EasyTAG, this padding is not automatic, but has to be specified by the user under Settings -> Preferences -> Tag Settings -> “Write the Track field with the following number of digits” (which I have set to 3, because I’ve never encountered an audiobook with more than 1000 files in it – 001, 002, 003, … 008, 009, 010, 011…).

Some more random tips from the Sansa forums (I haven’t verified that they are needed) is the following.

  • Do not specify the total number of tracks (like 01/87, 02/87, 03/87) because that may confuse the player. Just leave that field empty..?
  • Make sure that the GENRE tag is set to “Audiobook”…?

End of post.


The player will not handle the case with tracks in multiple subdirectories well. I think..? So one may as well move all files to one and the same directory, and then use EasyTAG to set the correct Track tag (NUMBER) on all of them. The following little script copies all mp3 files from within a directory tree to a directory named tmp. The file name of the new file while be $DIRNAME.x.$OLD_FILENAME (so that no filename information will get lost) rather than just $OLD_FILENAME.


mkdir tmp ;

find * -name *mp3 | while read FILE ; do
 NEWFILE=`echo "$FILE" | sed 's/\//.x./'` ;
 echo "Copying tmp/$NEWFILE" ;
 cp "$FILE" "tmp/$NEWFILE" ;

It would be cool if one could just create the zero padded track numbers command line (i.e without needing to open EasyTAG), using something like this:

for FILE in tmp/* ; do
  PADDEDNUMBER=`printf "%03d" "$NUMBER"`;
  echo "Tagging $FILE. Track number will be: $PADDEDNUMBER"
  # eyeD3 --track="$PADDEDNUMBER" "$FILE" | grep title
  # id3v2 --track "$PADDEDNUMBER" "$FILE"

I’ve tried both eyeD3 and id3v2. Neither seems to create the necessary padding of leading zeros (at least not if there are more than 100 files). So — EasyTAG it is!

StickyLookup for NetBeans

The following is a slightly more compact version of the elegant StickyLookup, first described by Ernest Lötter: http://netbeans.dzone.com/articles/sticky-lookup. Thanks, Ernest!

public class StickyLookup extends ProxyLookup implements LookupListener {
    private final Lookup.Result result;
    private final InstanceContent ic;

    public StickyLookup(final Lookup lookup, final Class<?> clazz) {
        this(lookup, clazz, new InstanceContent());

    private StickyLookup(final Lookup lookup, final Class<?> clazz, InstanceContent ic) {
        super(Lookups.exclude(lookup, clazz), new AbstractLookup(ic));
        this.ic = ic;

        this.result = lookup.lookupResult(clazz);
        this.ic.set(this.result.allInstances(), null);

    public void resultChanged(LookupEvent ev) {
        if (this.result.allInstances().isEmpty()) {
            // Wrapped lookup is empty. We pretend like nothing happened and keep 
            // exposing the same instances as before.
        } else {
            // Just copy whatever the wrapped instance has
            ic.set(result.allInstances(), null);

Invoking emacs daemon and client easily

UPDATE 2015-07-16 — this is much better: http://superuser.com/questions/358037/emacsclient-create-a-frame-if-a-frame-does-not-exist/862809#862809


# https://hugoheden.wordpress.com/2009/03/21/invoking-emacs-daemon-and-client-easily/
# This script will invoke emacsclient. If there is no emacs daemon
# running, then the daemon is automatically started.

# If any of -nw, -t or -tty, or for that matter -c or --create-frame,
# is specified on the command line, then the script will just pass on
# all arguments to emacsclient.

# But if none of that is specified, this script will assume that this
# is interactive usage. If $DISPLAY is set, the script assumes that
# the user would prefer to invoke the emacsclient with the --no-wait
# flag, opening the specified file (if any) in an existing frame (in
# the current $DISPLAY).  If there no frame currently open (in the
# current $DISPLAY) the script will add --create-frame as well.

# Because of --no-wait, it is not a good idea to let the EDITOR
# variable point to this script without command line flags. Suggested
# values for EDITOR would be "<script> --create-frame " or "<script>
# -nw"

# Tested with emacs 23.0.9 packaged for Ubuntu 8.10:
# $ emacs-snapshot --version
# GNU Emacs
# $ emacsclient.emacs-snapshot -V
# emacsclient 23.0.90


#set -x # Print lots of debugging info

  # Useful for prefixing printouts, and for self-invoking this script

  # This script can invoke itself by giving the --alternate-editor
  # option to emacsclient. The MUST_START_EMACS_DAEMON environment
  # variable is used to keep track on that:
if [ "x$MUST_START_EMACS_DAEMON" != "x" ] ; then
    echo "$this_script: Starting emacs --daemon. Ignoring all arguments: $@" >&2
    emacs-snapshot --daemon
      # No need to sleep or anything because the daemon will not fork
      # (return) until fully started.
    exit 1
      # We return an error code because starting the daemon implies a
      # previous failure to invoke the client. See usage below.

  # Internal helper function that invokes the client, but if that
  # fails at least daemon is started before an error code is returned.
function _invoke_client_orelse_start_daemon() {
      # Note that stuff printed to stdout may/will be interpreted by
      # caller... So be careful with printouts -- use stderr:>&2
      # This script itself is specified as --alternate-editor, and it
      # will make sure to (try to) start the daemon at least. See
      # above.
    emacsclient.emacs-snapshot "$@" --alternate-editor $this_script
    return $retval

  # Invokes the client. Also starts the daemon if necessary.
function _invoke_client(){
  _invoke_client_orelse_start_daemon "$@" ||
  emacsclient.emacs-snapshot "$@"

args=( "$@" )
  # Need to be careful to treat args as an *array*, so that command
  # line arguments are preserved until we pass them on -- even though
  # they may be containing spaces.. See `man bash` for more about
  # using parantheses for arrays, and about stuff like "$@" and
  # "${args[@]}"

if [ "x$DISPLAY" != "x" ] ; then
    for opt in "$@" ; do
	case $opt in 
	    -t)   user_has_specified_frame=true; break ;; # breaks out of the loop
	    -tty) user_has_specified_frame=true; break ;;
	    -nw)  user_has_specified_frame=true; break ;;
	    -c)   user_has_specified_frame=true; break ;;
	    --create-frame) user_has_specified_frame=true; break ;;

    if [ $user_has_specified_frame == false ] ; then
          # Hmm, is this the only situation where we want to add
          # --no-wait?
        args=( "--no-wait" "${args[@]}" )

          # display will contain something like "", ":0.0" or
          # "localhost:10.0" (including the quotes)
	current_emacs_displays=`_invoke_client_orelse_start_daemon --eval "(x-display-list)"` 
          # current_emacs_displays will contain something like (":0.0"
          # "localhost:10.0") current_emacs_displays may also be empty
          # if there was no daemon running, of if there is no frame
          # open.
	if [[ ! "$current_emacs_displays" =~ "$display" ]] ; then
              # If there is a match (display is included in
              # current_emacs_displays), then there is already a frame
              # open in this $DISPLAY. *Otherwise* we'll add the
              # --create-frame option to the array:
            args=( "--create-frame" "${args[@]}" )

fi # if DISPLAY

_invoke_client "${args[@]}"

# TODO: the "emacsclient || (emacsdaemon && emacsclient)" construct is
# ugly when the emacsclient call fails due to error in arguments --
# the daemon is invoked, but since it is already started a big error
# message is emitted -- FIXED -- now using the --alternate-editor
# mechanism, which works more gracefully.

# TODO: Check all if-statemenst for potentially empty values, for
# example "$current_emacs_displays" ..?



The host running dnsmasq:

1) Wherever  Static IP is configured the first “DNS Servers” entry  should specify and the second should specify (or whatever IP the nearest upstream DNS server has).

2) /etc/hosts.dnsmasq:


3)  /etc/dnsmasq.conf



I have a few computers at home (all running Ubuntu Linux 8.10, Intrepid Ibex) forming a small home network. I use dnsmasq to achieve the following:

  • Any host can be plugged in “without configuration”, i.e the dhcp-server functionality within dnsmasq is used.
  • After having been plugged in, hosts are able to ping or connect to each other by host name (thus not only by ip numbers), still without configuration, i.e that dhcp-server will be used together with the DNS functionality that dnsmasq provides.
  • Some of the hosts need a “constant” IP within the LAN (or “static” if you will, though using dhcp). This is needed for port forwarding to these hosts (so that they can be used for bittorrent and as various types of servers). We achieve this by letting dnsmasq manage a list of hostnames and their respective “constant” IP addresses within the LAN. So there is only one place within the whole LAN where that information is maintained, see below. The hosts themselves are still using zero configuration dhcp.
  • dnsmasq also works as a local dns cache for the LAN, which speeds up web browsing.
  • All this is very easy to set up

I tried for a while to set up a WINS server (using samba), but I could never really make that working..

A limitation is that the host running dnsmasq needs to be up pretty all the time (or at least whenever a host on the network needs web access). I have a desktop computer constantly turned on anyway (hosting a few server processes) that dnsmasq can run on.

Another option would be to install it dnsmasq on a router. This would be your only option if there is only Windows computers on your network, because dnsmasq does not run on Windows. I have no experience with this, but see for example Tomato Firmware.

So, how do we set up all this?

The host running dnsmasq has a static ip within the LAN. We want other applications on that same host to use dnsmasq for DNS services, and not some other DNS server on some other host. So, within Network Manager (or wherever that Static IP was configured) the first “DNS Servers” entry  should specify When the connection is enabled, NetworkManager will generate a /etc/resolv.conf containing something like the following:

# Generated by NetworkManager

By default, dnsmasq will read /etc/resolv.conf and use the hosts specified there (the lines starting with “nameserver”) as “upstream nameservers” to forward non-local DNS-requests to. In this case that file will point back to localhost (, see above. But that’s ok, dnsmasq will understand to ignore and look at the other lines in /etc/resolv.conf. In my case I will need to add the ip address that my adsl-modem has on the LAN, because the modem in turn is auto-configured by the ISP (dhcp) to know what dns servers to contact further upstream. So, within Network Manager (or wherever that Static IP was configured) the second “DNS Servers” entry  should specify When the connection is enabled, NetworkManager will then generate a /etc/resolv.conf containing something like the following:

# Generated by NetworkManager

Further, dnsmasq is configured to ignore the usual /etc/hosts and use a custom hosts-file instead, /etc/hosts.dnsmasq,  containing something like the following (“foohost” is the name of the host running dnsmasq)


/etc/dnsmasq.conf would then need the entry no-hosts to tell dnsmasq to ignore the usual hosts-file, and the entry addn-hosts=/etc/hosts.dnsmasq which specifies what file to use instead.


A suitable /etc/dnsmasq.conf is shown above. (As always, do a backup of the original before experimenting.) Most of the options are well documented elsewhere (for example in the example configuration file and the man-page). Note the dhcp-option=option:router, line which tells dnsmasq to tell any dhcp-clients what the gateway of the network is. In my case I’ve specified the address to my router.

Copy/paste with emacs in terminal

I often run emacs in a terminal window. The following is a way to get copy-paste “working” to and from other applications. Note that it requires xsel, “a command-line program for getting and setting the contents of the X selection”. See also http://shreevatsa.wordpress.com/2006/10/22/emacs-copypaste-and-x/

;; https://hugoheden.wordpress.com/2009/03/08/copypaste-with-emacs-in-terminal/
;; I prefer using the "clipboard" selection (the one the
;; typically is used by c-c/c-v) before the primary selection
;; (that uses mouse-select/middle-button-click)
(setq x-select-enable-clipboard t)

;; If emacs is run in a terminal, the clipboard- functions have no
;; effect. Instead, we use of xsel, see
;; http://www.vergenet.net/~conrad/software/xsel/ -- "a command-line
;; program for getting and setting the contents of the X selection"
(unless window-system
 (when (getenv "DISPLAY")
  ;; Callback for when user cuts
  (defun xsel-cut-function (text &optional push)
    ;; Insert text to temp-buffer, and "send" content to xsel stdin
      (insert text)
      ;; I prefer using the "clipboard" selection (the one the
      ;; typically is used by c-c/c-v) before the primary selection
      ;; (that uses mouse-select/middle-button-click)
      (call-process-region (point-min) (point-max) "xsel" nil 0 nil "--clipboard" "--input")))
  ;; Call back for when user pastes
  (defun xsel-paste-function()
    ;; Find out what is current selection by xsel. If it is different
    ;; from the top of the kill-ring (car kill-ring), then return
    ;; it. Else, nil is returned, so whatever is in the top of the
    ;; kill-ring will be used.
    (let ((xsel-output (shell-command-to-string "xsel --clipboard --output")))
      (unless (string= (car kill-ring) xsel-output)
	xsel-output )))
  ;; Attach callbacks to hooks
  (setq interprogram-cut-function 'xsel-cut-function)
  (setq interprogram-paste-function 'xsel-paste-function)
  ;; Idea from
  ;; http://shreevatsa.wordpress.com/2006/10/22/emacs-copypaste-and-x/
  ;; http://www.mail-archive.com/help-gnu-emacs@gnu.org/msg03577.html

Thanks to Nikolaj Schumacher and Miles Bader on the help-gnu-emacs mailing list for helping out.