Wednesday, May 6, 2015

Electron mystery on OSX solved

Do I look like an idiot? I don't know. But I felt like one for the last 2 days.


2 days ago I started to look into on a great project idea, to replace the Brackets Shell with Electron. Great idea! I wanted to contribute and fix issues that crossed my way. But, I followed the given instruction to clone the repo and setup all dependencies. After everything was download and in the right place, I ran npm start to bring up Brackets in it's new electron shell. But that first attempt failed with this error:
> Brackets@1.3.0-0 start ~/develop/fun/OSS/brackets-electron
> electron .

~/develop/fun/OSS/brackets-electron/app/shell-config.js:13
r CONFIG_PATH = path.resolve(utils.convertWindowsPathToUnixPath(app.getPath("u
                                                                    ^
TypeError: app.getPath is not a function
    at Object.<anonymous> (~/develop/fun/OSS/brackets-electron/app/shell-config.js:13:71)
    at Module._compile (module.js:418:26)
    at Object.Module._extensions..js (module.js:436:10)

I was wondering, if there was something important missing in the setup instruction, I simply made a mistake or my system config was tricking me. After checking with the guys who started that effort, I was left with this weird error.

I started to research and looked for others having the same issue, but I couldn't find anything. Okay, it has to be my machine setup. Back at home, I started to setup everything on another machine to see if it works there. The result was the same! The error showed up on a different Macs, with a different OSX versions.

I went back to our slack channel and carefully mentioned, that I'm still not able to get it running yet. Someone replied, that I can install Electron globally and try it again. But this turned out to be a red herring. Nothing has changed and it was really frustrating, since nobody else seemed to have these issues on OSX. I promised them to help, but I could even review and test pull requests.

I did some more research and came across this great blogpost from Thorstenhans. He provided a boilerplate project for an app that uses Electron. I was so happy. I followed his instructions to create a clean app. Everything went fine and I was excited because it's using es6. Unfortunately, the result with Electron was the same.

I left a comment for the blogpost asking, if he has encountered this issue before. Nothing worked for me as expected. So, it must be my machine I concluded. But two machines at the same time?

I mentioned my inability to launch Electron on OSX, briefly in the slack channel for electron-brackets. I felt like an idiot at this point. Somebody who distracts everybody with some nonsense. Nobody had an idea what might help to resolve this misery to help me getting started.

Since the electron-brackets version on Linux seemed to work fine, I decided to pull my Linux VM out of the drawer and give it a try. I cloned the repo, installed everything and typed npm start at the console. Guess what? It worked! I was happy. That is awesome and I'm finally able to help.

But I wasn't happy that my day-to-day machine didn't play well with me. I had a conversation with Thorsten Hans (look at the comments here). He solved another mystery for himself along the way, but I didn't make any progress.

Long story short, I started to get rid of my nodejs installation, install nvm from scratch and hoped to resolve the issue. No luck. But then I inspected the environment variables for anything nodejs related and I found NODE_PATH. It seemed somehow messed up. This post recommended to undef NODE_PATH to solve another issue. But it helped me too. npm start is finally working and the biggest mystery, that let me look like an idiot was resolved.

Thanks

To Thorstenhans for the back and forth to help me resolve the issue. Thanks to Andrew MacKenzie to mention often enough, that the Linux version is doing a good job for him.

Friday, January 2, 2015

Something I Learnt About sed

Note: I’m writing this down to remind myself for the next time I’m using sed and any kind of regex.

I was working on some very simple task: replace a string in a file with a different string.
All of this should happen on our build machine during the product build. Nothing too fancy. But then I got bitten by different versions of sed available on the build machines.
We build our product on OSX, Windows and Linux and I had to realize, that the regex I used, didn’t work with every sed version on the build machines.

My Regex Confusion

To make it clear: I’m not a regex guru. I use it for simple things. When it get’s complex, I usually consult some tools like regex101.com to get it right.
I started with this simple regex to replace the number after the - (the number of commits). The buildnumber looks like 1.0.0-12345.
Here is the command I started with
`cat build.prop | sed "s/(brackets_build_version=\d+.\d+.\d+-)(\d+)/\1${NEW_COMMITS}/" > build.prop.new`.
The result:
`sed: 1: "s/(brackets_build_versi ...": \1 not defined in the RE`
Okay, that doesn’t help that much. After some research I have found the solution: -E needs to be added to the command.
Okay, that error went away, but the replace didn’t work either. Hm, now I had to debug the Regex and find the issue.
After several rounds of experimentation, I started to read the documentation for re_format. That explained a lot: there are modern RE and obsolete RE (they are sometimes referred to as Basic Regular Expression (BRE) and Extended Regular Expression (ERE)), that mainly exist for backward compatibility. They are not as powerful as the modern RE and lack some features.
The last working version looked like:
`cat build.prop | sed -E "s/(brackets_build_version=[[:digit:]]+.[[:digit:]]+.[[:digit:]]+)-([[:digit:]]+)/\1-${COMMITS}/"`
This worked! Heureka.
But wait, why do I have to used [[:digit:]] instead of the much shorter \d+? I don’t know and probably I will never find out. 

Deploy on Build Machines

Happy, that I finally found a solution that worked on OSX. I totally forgot about the other OSses. Once I made the changes and started the build, it failed on Linux and Windows.
WTH? What was I missing? Why doesn’t it even work on Linux? Quickly started my Linux VM and gave it try. The solution was simple: I had to call sed with -r in order to make it work.

Conclusion or What I have Learnt

sed behaves differently on different OS versions. This is probably no exciting news, but I thought I keep this as a reminder for myself.
Using bash or some derivative of it like cygwin or gitbash on Windows does make a difference for some tools. Especially sed comes in two variants: BSD and GNU.
OSX uses BSD and I guess linux and cygwin come with GNU. They might have different command line switched for the same option. So be careful and testing is always required.
Another difference is the Regex engine tha can be used. sed supports basic regular expressions (BRE’s) and extended (ERE or modern) regular expressions
As I mentioned bofore, enabling the extended regular expressions you need to call sed -E on OSX and sed -r on Linux and cygwin.

Saturday, November 29, 2014

Moto 360 - Was ich wollte und was ich bekam

Heute vor 2 Wochen (17. September) 10 Wochen habe ich von einem Freund eine Moto 360 geschenkt bekommen. Der Grund: er hat als Teilnehmer der Google I/O eine zugeschickt bekommen, hat aber selber kein Android Phone und somit keine Verwendung dafür. Ich hab mich sehr darüber gefreut, wollte ich mir doch selber eine kaufen. Leider, in diesem Fall eher Glück, war die Uhr bei Motorola innerhalb kürzester Zeit ausverkauft und ich hab keine mehr bekommen. Naja, ich hab mich auf eine etwas längere Wartezeit eingestellt. Umso überraschender war dann die Lieferung an mich.

Erwartung

Was habe ich von dieser Uhr alles erwartet? Die Artikel, in denen über die Uhr geschrieben wurde, haben sich ja vor Begeisterung gar nicht mehr einbekommen. Ich denke, dass sollte sich bei erscheinen der Uhr etwas legen. Das ich seit 1,5 Jahren eine Pebble Smartwatch habe, bin ich schon mit einer hohen Erwartungshaltung angetreten. Darunter waren
  • Akkulaufzeit von mindestens 3 Tagen
  • Herzfrequenzmesser für sportliche Aktivitäten (Ersatz für Brustgurt)
  • Schlaftracker
  • Eine Uhr im coolen Design und coole Watchfaces

Der erste Tag

Ich hab die Uhr nur noch auf die Ladestation gestellt und bis zum nächsten Morgen gewartet. Der Tag fing erstmal mit einem Update an. Ich hatte das am Abend zuvor nicht mehr gesehen und deshalb wurde die Uhr jetzt erstmal aktualisiert. Schon mal nicht schlecht. Die ersten Probleme haben sie (Motorola) also schon beseitigt.

Nachdem das Firmware Update durchgeführt und die Uhr endlich einsatzbereit war, hab ich erstmal ein bisschen rumgespielt. Leider hat dadurch die Batterielaufzeit sehr gelitten. An diesem Tag war die Uhr Nachmittags um 16 Uhr fertig. Aus, Ende und vorbei. Wow, das war sehr viel weniger als ich erwartet hatte. Am nächsten Tag habe ich dann tatsächlich das Ladegerät der Uhr mit ins Büro genommen. Ich wollte ja nicht mit einem unbrauchbaren, weil leerem, Hightech Spielzeug rumlaufen. Schon echt blöd, für etwas was eigentlich die Uhrzeit anzeigen soll. In den folgenden Tagen habe ich die Uhr weniger benutzt, ausser um die Uhrzeit abzulesen. Auf jeden Fall hielt die Batterie jetzt bis Abends um 9 Uhr. Das war aber immer noch nicht das, was Motorola auf ihrer Website verkündet hat: Hält einen ganzen Tag. Vielleicht haben wir unterschiedliche Vorstellungen wie lang so ein ganzer, normaler Tag ist.

Alles wird besser oder das große Firmware Update

Die ersten Wochen waren eher ernüchternd. Die Batterie war schnell erledigt und Bedienungstechnisch gab es auch noch einiges zu verbessern. Okay, so ist das eben, wenn man mit einem neuen technischen Spielzeug spielen möchte. Die Ecken müssen erst rundgeschliffen werden. Warum sollte das bei der neuen Smartwatch anders sein? Umso erfreuter war ich, als dann eines Tages die Verfügbarkeit eines Firmwareupdates angezeigt wurde. Also, die Uhr schnell auf die Ladestation und dann das Update starten. Auf den ersten Blick hat sich erstmal nichts verändert. Unter der Haube wurde auf jeden Fall der Batterieverbrauch reduziert. Super! Endlich hält die Uhr einen ganzen langen Tag durch (bei moderater Benutzung!).

Firmware Update die Zweite

Ein paar Wochen später gab es dann Update Nr. 2. Hier wurde hauptsächlich die Bedienbarkeit der Uhr verbessert. Notifications können jetzt ganz aus dem Sichtfeld an den unteren Rand verschoben werden. Damit kann dann die Uhr komplett betrachtet werden. Weiterhin soll die Bluetooth Verbindung mit dem Smartphone jetzt stabiler sein.

Was ist aus den anderen Wünschen geworden?

Herzfrequenzmesser

Der Herzfrequenzmesser ist, ich sag es mal vorsichtig, nicht ganz so gut wie ich mir das vorgestellt habe. Messungen dauern zu lange und eine kontinuierliche Messung ist anscheinend nicht möglich oder die Apps unterstützen das einfach noch nicht. Messungen funktionieren in vielen Fällen nicht beim ersten mal. Die Uhr legt großen Wert auf die richtige Armhaltung. Der Kontakt zwischen Uhr und Haut muss komplett hergestellt sein. Vielleicht passiert hier ja noch etwas zum besseren. Momentan gehört das noch in die Kategorie "Nutzlos und Überflüssig".

Schlaftracker

Okay, ich hab dann mal ausprobiert ob ich die Uhr auch zum Schlaftracking benutzen kann. Ich bin um Mitternacht ins Bett gegangen und die Uhr war zu 100% aufgeladen. Als ich am morgen um 6:30 h aufwachte, war sie... Aus! Alle! Leer! Unfassbar. Ich weiss ja nicht was die Uhr so zum Schlaftracking macht, aber das ist mehr als enttäuschend. Da hatte ich mal wieder mehr erwartet.

Lederarmband

Was ich bis jetzt gar nicht nachvollziehen kann, ist die Tatsache das eine Uhr, die jeden Abend aufs Ladegerät gelegt werden muss, mit einem herkömmlichen Lederarmband ausgestattet wird. Das Armband wird ständig an der selben Stelle geknickt und sieht mit der Zeit nicht mehr schön aus. Für eine Uhr, die zum Sport getragen wird, halte ich Lederarmbänder auch nur für bedingt brauchbar. Duschen ist auch keine gute Idee, da das Leder darunter sehr leidet. Ich hätte mir gewünscht, das die Uhr auch mit einem Metallarmband verkauft wird. Diese Option stand leider nicht zur Verfügung, soll aber zum Ende des Jahres erhältlich sein. Ich bin gespannt. Ich werde mir sofort ein Metallarmband besorgen.

Fazit oder was ich bekam

Um noch auf den Punkt "Erwartungen" zurückzukommen. Leider habe ich mir viel gewünscht und nicht so viel bekommen. Akkulaufzeit war am Anfang mehr als enttäuschend. Weniger als ein Tag durchgehalten und das "Mitschleppen" des Ladegeräts für die Uhr geht gar nicht. Das wurde besser mit dem ersten "großen Firmware Update". Das Update hat vieles verbessert. Bei 3 Tagen Batterielaufzeit bin ich trotzdem noch nicht angekommen. Aber immerhin bei der Hälfte.

Bleibt also noch eine Uhr im coolen Design. Jawoll, das ist auf jeden Fall erfüllt worden. Die Uhr sieht gut aus, die bisher erhältlichen Zifferblätter sehen gut bis originell aus. Immer mehr Apps bekommen die Möglichkeit Informationen auf der Uhr darzustellen.

Ich benutzte die Uhr jeden Tag. Sie hat sich zu einem zuverlässigen und unauffälligen Begleiter entwickelt. Die Spracheingabe funktioniert, zumindest in Englisch, überraschend gut. Zum Sport benutze ich die Uhr nicht. Aus irgendeinem nicht offensichtlichen Grund steigt der Batterieverbrauch während dieser Zeit erheblich an. Ich benutzt die Smartwatch als Schrittzähler und Activitytracker (hauptsächlich Radfahren). Ich glaube, dass es noch viele Verbesserungen geben wird. Die Pebble Smartwatch hat auch mit relativ wenigen Features angefangen und wurde mit der Zeit immer leistungsfähiger. Also abwarten und geduldig sein.

Pros und Cons

Pro

  • Ladezeit
  • Bedienung
  • Induktionsladegerät

Con

  • Batterielaufzeit
  • Lederarmband
  • Schlaftracking

Kaufen oder nicht?

Thrillseeker? Spielkind? Muss ich immer das neueste, coolste technische Gadget haben? Dann gibt es nur eine Antwort: Kaufen! Die erste gut aussehende Smartwatch, die nicht wie ein merkwürdiger Klotz am Handgelenk aussieht. Naja, zumindest nicht an meinem Handgelenk. Wie es sich aber immer so mit neuem technischen Spielzeug verhält, gibt es noch einiges zu verbessern.

Aber anscheinend gibt sich Motorola hier viel Mühe die Kunden mit aktualisierter Firmware und besserer 3rd Party Integration glücklich zu machen. Und nicht vergessen, wir haben es hier mit einer jungen, neuen Produktgeneration zu tun. Es wird noch viel passieren in den nächsten Wochen und Monaten. Google Fit ist erst der Anfang.