Donnerstag, 13. März 2014

command line fu on mac osx

On the linux command line (as in emacs) it's easy to jump words:
Terminal on Debian
Ctrl+f jump one word forward
Ctrl+b jump one word backward

To get the old feeling from the linux command line (and a lot of additional functionality) get iTerm2 and adjusted some key bindings in the preferences:
iTerm2 on Mac OSX
Alt+f jump one word forward
Alt+b jump one word backward


Examples of what you can do with the command line? http://www.commandlinefu.com

using uml to get to know fresh code

I recently had to adapt quite a pile of code for android. To get to know to the classes and their dependencies and life cycles I started drawing UML class and sequence diagrams (inspired by the book Head First OOA&D). Eclipse has some really nice shortcuts to navigate in code (Cmd+Space to jump to the declaration, and Ctrl+Alt+h to show references) but nevertheless it's hard to keep a bird's eye on the code.
This is one my first class diagrams for using the camera:
I pretty sure that I got some symbols (arrowheads) wrong, but I the idea was to simply get an overview. The code for this CameraPreviewTest class can be found at https://github.com/michaelhaberler/MIY. After a couple of diagrams I wanted to store and edit the diagrams for documentation purposes. So I looked around for some UML editors which allowed me to create and update my diagrams quickly:
  • http://www.draw.io
    Updated class diagram:

    Sequence diagram to visualize a route of calls and callbacks to setup the android camera and some additional view classes:
  • http://www.umlet.com/
  • AmaterasUML
    AmaterasUML was arguably the quickest to create very detailed UML class diagrams. It's an eclipse plugin and I just had to drag the classes from the package explorer into the editor window.

Donnerstag, 28. November 2013

restore content from time machine backup one by one

After a clean OSX install I wanted to restore the content of the time machine backup one by one. This way I could leave out old junk content and applications that have accumulated over the time.
I had to do a clean install after I had to bring my mac to Mc Shark to repair my busted graphics card. The people at Mc Shark asked me for my administrator password but I would rather have them wipe my hard drive before I would hand them my password. (What do we have the time machine for?)
So they wiped my hard drive and I set up the mac from scratch - a clean install. I did not restore the user profile from the time machine backup during the OSX install or using Migration Assistant afterwards. I simply used Finder to copy each file or directory from my time machine backup to my new install. Even for things like emails or passwords that are not as easily accessible as - say - pdf documents this worked surprisingly well.

In Finder I navigated to the device where time machine has created the backup Computer->My Book->Backups.backupdb->Michaels Mac. There I could find all the backups that time machine has created sorted by date. The latest, most recent, backup was even named Latest to make it stand out.

I have a late 2011, 17'' MacBook Pro with Mac OSX 10.9 installed (after updating from 10.7 to 10.8 and then to 10.9). Also I noticed that the file structure changed slightly after the clean install.

So here's how I restored the content one by one:
Navigate to
Latest->Macintosh HD->Users->michael
and hit Cmd+Shift+G and type Library to gain access to this hidden folder. Now I am in
Latest->Macintosh HD->Users->michael->Library
(Actually, with a short terminal command it's possible to display all hidden files.)

All passwords saved to the keychain
Copy
Latest->Macintosh HD->Users->michael->Library->Keychains
to the corresponding location in your new installation. For this I opened a second Finder window and navigated to the hidden Library folder of my new user profile. Then I could copy via drag and drop. Also, since the installation was still clean, I have faithfully overwritten the existing folders.

All emails and all email settings
Copy
Latest->Macintosh HD->Users->michael->Library->Mail
and copy
Latest->Macintosh HD->Users->michael->Library->Mail Downloads

The Mail app did take some time to do some processing after its first start.

iTunes library
Copy
Latest->Macintosh HD->Users->michael->Music->iTunes

iPhoto library
Copy
Latest->Macintosh HD->Users->michael->Pictures

Afterwards I had to specify the location of the iPhoto library I wanted to use (the folder I copied from my backup).

.emacs, .vimrc, .bash_profile
It's also possible to make Finder display hidden files
defaults write com.apple.finder AppleShowAllFiles -bool true
killall Finder


Mittwoch, 30. Oktober 2013

memo: working with eclipse

  • installed Vrapper to keep my hands on the keyboard 
  • use the same configuration as in vim
    ln -s .vimrc .vrapperrc

Eclipse
Ctrl+F11 Run
Ctrl+o/Cmd+Space Jump to declaration
Ctrl+Alt+h Show references

Android emulator
Home home
F2 left softkey
Shift+F2 right softkey
Esc back
Ctrl+F11 portrait - landscape forward
Ctrl+F12 portrait - landscape backward

Montag, 18. Juli 2011

Sharing data among Mathematica notebooks

With time my Mathematica-notebooks increase in size and complexity. That's when I decide to split my notebooks into several files. Also, sometimes I want my results out of the notebooks which possibly change upon each evaluation.

One way is to create a package stored to a notebook (.nb-file) which is convenient for function definitions. Another way is to write Mathematica expressions to an ASCII-file with the suffix ".m" with the command "Save".

Here, I have some expressions:

f[x_] := x Log[x]
a = Table[f'[i], {i, 0.1, 1, 0.1}]
p = ListPlot[a]
ascii = FromCharacterCode[Range[32, 126]]

With this command I can retrieve the names of the expressions in the "Global" scope, or context:

Names["Global`*"]

And finally, this is how I store all expressions which have names starting with "a" to a .m-file:

mfile = NotebookDirectory[]~StringJoin~"results.m"
Save[mfile, #] & /@ Names["Global`a*"]

In another notebook I can load these expressions like this

<<results.m;

The .m-file itself looks this way:

a = {62, 58, 46, 115, 47, 77, 110, 111, 72, 94}
ascii = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

Freitag, 8. Juli 2011

How to create publication style figures with Mathematica

Recently, I've been using Mathematica a lot - both for data processing and analysis as well as for plots. Plotting is easily done and quite selfexplaining, or at least well documented. Publication style figures of plots have little more demands: labled axes, legends, etc. I tinkered around quite a lot with such figures and I'd like to share my output:

As said a good looking plot can be created quite fast:

<< PlotLegends`

l1 = RandomReal[{2900, 3100}, 10]

fig1 = ListPlot[{l1, l2},
  Joined -> True, PlotStyle -> {Red, Green},
  PlotMarkers -> Automatic,
  PlotLegend -> {"list1", "list2"}, LegendShadow -> None,
  LegendPosition -> {1.1, -0.25}
  ]




A figure with two plots and the legend having its own part requires some more code:

pm = {Graphics[{Red, Disk[ImageScaled[{0.5, 0.5}], .025]}],
  Graphics[{Green, Disk[ImageScaled[{0.5, 0.5}], .025]}]}
pm2 = {
  Graphics[{Red, Disk[ImageScaled[{0.5, 0.5}], .25]}],
  Graphics[{Green, Disk[ImageScaled[{0.5, 0.5}], .25]}]
  }

fig = Show[
  GraphicsRow[{
    ListPlot[{l1, l2}, Joined -> True, PlotMarkers -> pm,
     PlotStyle -> {Red, Green}],
    Graphics[
     Legend[Transpose[{pm2, {"list1", "list2"}}],
      LegendShadow -> None]],
    ListPlot[l3, Joined -> True, PlotStyle -> Black,
     PlotMarkers -> Automatic]},
   ImageSize -> Full
   ],
  Graphics[Text[Style["(a)", 14], {0, 20}]],
  Graphics[Text[Style["(b)", 14], {400, 20}]],
  Graphics[Text[Style["(c)", 14], {800, 20}]](*,Frame->True*)
  ]



Unfortunatly, the figures shown are in "PNG" format and they do not look as nice as in "EPS" format. (For some reason I can't upload "EPS" formatted pictures.)

Montag, 4. Juli 2011

Computermodel of the Protein "Ubiquitin" in a Hydrated Ionic Liquid

everything that living things do can be understood in terms of the jiggling and wiggling of atoms - Richard Feynman
In this spirit I am studying biomolecules using computer simulations.

These two pictures show the model: The protein "ubiquitin" in a hydrated ionic liquid as solvent.

(a) The protein is represented by van der Waals balls, the hydrated ionic liquid by a transparent green mass and the simulation boundaries, a truncated octahedron, by black lines.

(b) Same as in (a) except that the solvent is reduced to solvent molecules within a 10 angstrom radius around the 76th amino acid of ubiquitin.