Face the Facts. Then Act.

Quote

“Face the facts. Then act on them. It’s the only mantra I know, the only doctrine I have to offer you, and it’s harder than you’d think, because I swear humans seem hardwired to do anything but. Face the facts. Don’t pray, don’t wish, don’t buy into centuries-old dogma and dead rhetoric. Don’t give in to your conditioning or your visions or your fucked-up sense of… whatever. FACE THE FACTS. THEN act.”

From Quellcrist Falconer’s speech before the Assault on Millsport. Quellcrist Falconer is a character occuring in some novels of Richard Morgan. The mentioned quote is from Broken Angels by Richard Morgan, published in September, 2008.

Face the facts, then act on them is one of the most important philosophical quotes for me. And yes, it is from a science fiction novel. I take most of my philosophical inspiration from science fiction novels. 😉  Don’t you?

If you have any kind of problem as a developer or in your life in general, treat it in the light of Quellcrist Falconer’s quote. It may help you quite much. It definitely has helped me.

This will consist of two steps.

  1. Face the facts.
    This means, look at the facts, look at all the facts. Especially, look at those facts which you don’t want to be true. Look directly into the eyes of the cruelest facts. Acknowledge their existence.
  2. Then act on them.
    Only looking for the facts and pondering and ruminating the facts and how bad the world is, is not an option. Ponder about them and then act. Only through action, you’ll make the best of any situation.

Which bits of wisdom do you consider most important?

How do You Move Cygwin?

Last week, I had to move Cygwin from my old to my new working PC.

I can tell you, starting new with Cygwin is a completely different thing than copying or moving a working installation to another PC after four years of not updating it. I spent one and a half days on the task and it still does not work exactly like it did before … but I can use it productively. And it was worth the trouble. 😉

What follows is my personal moving cygwin leaflet.

How do I copy or move Cygwin from PC 1 to PC 2?

As said, it was not easy and I had to follw many blind alleys and got lost in the mazes of the Cygwin forums a lot ….. I’m leaving away some of the blind alleys and all of the system reboots in the following description.

  1. Zip the cygwin directory on PC 1. On my PC 1, it is located under C:\cygwin. It contains cygwin’s setup.exe and the packages directory and the bin, usr, etc, lib … directories.  I zipped it to c-cygwin.7z.
  2. Zip the user’s home directory on PC 1. My cygwin username on PC 1 was ‘wic’, and the home was located under D:\wic. I zipped it to d-wic.7z.
  3. Unzip the c-cygwin.7z on PC 2 to C:\cygwin.
  4. Unzip the d-wic.7z, ideally to D:\wic. But my PC 2 has no D:\ drive and I don’t want to repartition it now. So I extract it to C:\wic.
  5. Run c:\cygwin\setup.exe. Select “Install from local directory”. Select “c:\cygwin” as root directory. Select C:\cygwin\packages as local package directory. Click Next, Next, … until setup.exe ends.
  6. Set the Windows environment variable HOME for your user to /cygdrive/c/wic. Literally, as cygwin like path.
  7. Now I can doubleclick my C:\cygwin\cygwin.bat file and it tries to run my olde .profile and so on…..But, I get some strange errors like

    bash: $’\r’: command not found

  8. I’m assuming my .profile has Windows- line-endings but the drive is mounted in binmode. I call ./mount and get

    c: on /cygdrive/c type system(binmode,noumount)
    d: on /cygdrive/d type system (binmode,noumount)

    I call ./od -c ~/.profile  and see a lot of \r\n. So my assumption seems plausible.

  9. I’m trying to remount in textmode: mount -t c:\cygwin /cygdrive/c but I’m getting this error: mount: /cygdrive/c: Device or resource busy.
  10. Somewhere in the net they say if this error occurs, you should unmount first. I’m trying umount -A, and there is no error message. But still, the binmode-mounts stay. I cannot not remount c: as textmode.
    During all the reading in the forums, I find out that the cygwin maintainers changed the treatment of line-endings totally around 2011. I think there’s no way to resist these changes….. After four years, finally I have to update my cygwin.
  11. I download and install the newest version of cygwin. At least the PATH variable is now set correctly, I can call cygwin commands now from every folder as long as I’m inside the bash.
  12. I’m mounting mkdir /c; mount C: /c   Seems to work. Still the mounting of my home directory is wrong.
  13. I’m moving c:\wic to c:\cygwin\home\wic and setting the HOME environment variable to /home/wic. Still, it cannot interpret the windows line endings correctly.
  14. I’m calling d2u (dos2unix) for the most important files:
    cd /c/cygwin/home/wic
    d2u .*   # this works, d2u ignores binary files and directories
    d2u *
    cd bin
    d2u .*
    d2u *
  15. cp /bin/bash.exe /usr/local/bin/bash.exe  # because some of my bash scripts use #!/usr/local/bin/bash
  16. Copy scripts from c-cygwin.7z/usr/local/bin to /usr/local/bin, running d2u * in /usr/local/bin.
  17. When I close the cygwin window and start it again, the mount of c: -> /c is away. Maybe because of lacking rights? I try to start cygwin with admin rights and do the mount again. No, it’s not a rights problem, but mount does only create temporary mounts. If you want to have persistent mounts, you have to change the /etc/fstab file.
  18. Also, I want to replace the /cygwin prefix by /, so that cd c:/ can be written as cd /c.  In the /etc/fstab, replace this line
    none /cygdrive cygdrive binary,posix=0,user 0 0
    this:
    # getting rid of /cygdrive and make all new mounts text mounts.
    none / cygdrive text 0 0
  19. Hooray hooray. Now, I can use all of my scripts, my aliases and all of the un*x commands that come with cygwin. Only some fine tuning is lacking.
  20. Create a shortcut on the screen to Cygwin.bat.
  21. Select the little tree as icon for the shortcut. The tree is my bash symbol for ages. (pic)
  22. Double click it. Right-click on the window header. Select Properties. Choose these properties:
    Quick-Edit-Mode: on
    Insert-Mode: on
    Font:7×12
    Window buffer size: w x h 120 x 3000, window size: 120 x 43
    Window background color: 244,244,188
    Window text color: 0,10,10

cygwin

DONE.

WinDirStat: Find Harddisk Memory Monsters

Wicker’s Lemma to Moore’s law:
Every hard disk gets full, independent of its size.

Astonishing, but true. If When your hard disk gets full, you can do two things:

  • Clean it up
  • Buy a new one

Of course, when your harddisk gets full late saturday night and you need some more space now, buying a new one is not an option. Also, if the harddisk in your laptop gets full, buying a new one will come with a lot of work: Transferring all the data, programs and the OS to the new harddisk. This is not something you really want to do! So often cleaning up is the only option.

How do you clean it up? First, empty the trashcan. This may already be enough. If it isn’t, download WinDirStat for Windows (or KDirStat for Linux or Disc Inventory X for Mac), install and start it. It will scan your harddrives and create a nice looking view where you can see exactly what consumes the most space on your drive. Every file is represented by a rectangle and the size of the rectangle is proportional to the size of the file.

It is indeed enjoying to use this tool for hunting and killing those evil memory monsters. It may be more enjoying than killing pigs with birds 😉 Happy hunting!

02-15 13-WinDirStat

WinDirStat is free software, GPL’ed.

Cygwin: Linux Commands on Windows

Maybe you – like me – have learned to know and love the linux bash with its pipes and filters and its standard commands like sed, grep, find, awk, alias, xargs and so on. Maybe you have to do anything with the Windows batch or Windows command shell now. Then you will not only feel like in the stone age, but you’ll feel personally insulted by how ugly, impractical and unusable the Windows tools are.

02-13 15_44_44-Cygwin Setup

You’ll long for your precious bash and your beloved grep. You are not alone…. That’s why since 1995 people are working on Cygwin. Cygwin is a bash with a huge lot of commands, usable on Windows.   I have been using it now for more than ten years, and there have not been too many working days when I haven’t used it for this or that. I only can recommend it warmly for bash addicts coming to Windows.

To start using it, just download the latest Cygwin installer and run it. You’ll be firing your first find | xargs | grep in a quarter of an hour. It’s that easy.

Though it has some quirks, it can be used quite well as your personal shell on Windows PCs. (I would not recommend to use it on a build server or as part of the software build process. Because of the quirks and because it would be an administration nightmare.)

When it works, it works well. I have not updated one single package of the Cygwin installation on my working PC since 2009…. This week, I had to move the Cygwin to my new working PC. But this is another story.

I’d love to hear from you: Which shell do you use on Windows? Why?

 

What are the quirks, you are asking?

In short: line endings.

Unix line endings are \n, Windows line endings are \r\n. This leads to a whole lot of problems which have never been solved well by the Cygwin developers. And I assume these problems cannot and will not ever been solved well.
Because of the different line endings you have such strange things as being able to mount a directory in textmode or in binmode.

Some Cygwin commands do different stuff, depending on the mount mode of the stuff. When the stuff comes from a binmode mounted directory, it is treated differently than when it comes from a textmode mounted directory.  But not all Cygwin commands do the same. Some treat stuff like this and some like that. And of course, it also depends on the version of the tool. And, as some commands create temp files, your result may also depend on the mount mode of your temp directory.

It may be that cat foo | grep bar  results in different line-endings than grep bar foo.  And that grep bar foo | awk // gives a third type of line-ending. There even have been versions of Cygwin where the commands also differentiated between different path notations.

All of this binmode/textmode/line-endings stuff is just !$%!$%!$.

And you’ll end up with files having \n as line-endings or even \r\n\n or probably anything that matches [\r\n]+ where they should just always have \r\n. This will happen, when you are using Cygwin in a regular way. Mostly, it is just a call of u2d (unix2dos) or some similar command and the file is correct again.

 

SumatraPDF: A Fast and Light PDF Viewer

Every computer user – and hence every developer – needs to view pdf files from time to time. Adobe’s pdf viewer is the bloatware par excellence, slow and famous for its security problems. Security problems which make you need to update it every week or so.

Firefox has a built-in pdf viewer. But the pdf viewer that is built into Firefox is also quite slow and it creates very often a terrible ugly scripture. Sometimes, the text is nearly unreadable with the Firefox built-in pdf viewer. See this example, it is at zoom factor 100%, rendered with the Firefox 26.0 built-in pdf viewer.

02-08 12_21_46-.NET Format Strings - DotNet-formatting-strings.pdfThe scripture is ugly, isn’t it?  After some search, I came across SumatraPDF, and I’m using it ever since. I love it. It is

  • lightning fast
  • lightweight
  • creates readable and beautiful text
  • probably much more secure than Adobe’s viewer
  • open source

Here is the same text rendered with SumatraPDF 2.4, at zoom factor 100%:

02-08 12_22_06-DotNet-formatting-strings.pdf - [.NET Format Strings] - SumatraPDFCan you see the difference? The letters are much prettier and they are not intermingled falsely as with Firefox’ viewer.

I highly recomment SumatraPDF. Not only me, but also the Free Software Foundation.

 How to make SumatraPDF the viewer used by Firefox:

  1. Install SumatraPDF.
  2. Open the settings dialog in Firefox.
  3. Select the applications tab.
  4. Scroll down to Portable Document Format (PDF).
  5. In the dropdown-box, select SumatraPDF Browser Plugin.

What is your favourite PDF viewer and why?