Anders Tornblad

All about the code

Label archive for utility

Trying out Visual Studio Code

Yesterday Microsoft held Build 2015 and presented lots of nice things to the developer community. I have always loved Microsoft's developer tools, and started using Visual Studio back in 1997, hacking away with Visual Basic and Visual C++.

Now I still use Visual Studio at work, but for my personal projects, I mostly do web development in PHP and sometimes ASP.NET MVC. For the PHP projects, I have been using Komodo Edit for a while now, and am happy with it.

Visual Studio Code

After a quick download and a smooth installation, Visual Studio Code booted. I opened a folder full of PHP and JavaScript files. Syntax highlighting, bracket matching, syntax errors and warnings work really well for PHP, JavaScript, HTML and CSS, but PHP IntelliSense isn't included in this Preview version, which unfortunately means I won't be switching. Yet. However, JavaScript IntelliSense is amazing! It found a rookie mistake for me...
Don't do bitwise operations on bool

IntelliSense in Visual Studio Code is really good in every language it supports. Code completion and suggestions for JavaScript, HTML, CSS, SASS and C# are instant, but some features are missing from HTML IntelliSense.

A couple of HTML IntelliSense suggestions

  • Allowed attribute values should be suggested, like when typing <link rel=", I would like a popdown list to suggest things like stylesheet and so on.
  • Element suggestion should only include elements that make sense in the context. Directly inside an <ul> element, there is no point in suggesting a <blockquote>. Only <li>, <script> and <template> elements make any sense.

Bad elements in UL

What will make me switch

The editor is really nice to work with, it feels snappy and does things well. Changing personal settings is done in JSON, which is cool, because JSON... Until PHP IntelliSense is added, and some improvements are made in HTML editing, I will stick to Komodo Edit, but I will probably switch to Visual Studio Code eventually.

Tajmkiper now public

Today I launch Tajmkiper as a publicly available, free-to-use, utility. You are welcome to use it as much as you want. If you like it, please tell your friends and colleagues about it.

It is designed mobile-first, so it really looks its best on a smaller screen, but works fine in any modern browser.

Try it out:

Read more about it:
Tajmkiper, part 1
Tajmkiper, part 2
Tajmkiper, part 3

Using addTouch to emulate webkit touch events in desktop browser

Testing multitouch code on the iPhone is a bit tedious. I don’t have a Mac, so I don’t have access to the iPhone emulator. I do have a tiny web server installed on my development machine, so I mostly open the project on my iPhone over Wi-Fi using a local IP address. That way I can test my new features instantly, and verify that some bug has been fixed.

This has been enough for simple experiments, but when the code is to be used in a production environment, I really need the debugging capabilities of a modern desktop browser. Mobile Safari does have a developer mode, but that only catches JavaScript exceptions and presents them in a list. I need to be able to set breakpoints, and step through my code in a debugger. I need FireBug, or the Developer Tools of Google Chrome or Internet Explorer 9.

That is why I wrote addTouch. AddTouch started out as a Google Chrome Extension to simulate touch events using the mouse in any web page. Unfortunately, the security model of Google Chrome doesn’t allow me to take over the mouse input completely using an Extension, so instead it is now a JavaScript file to be included before all other JavaScript in the page. It also comes with a CSS stylesheet.

When you visit a touch-enabled web page that includes addTouch.js on an iOS device, nothing out of the ordinary happens. The web page simply works as intended. But when you visit the same web page using any modern desktop browser, adding ?_addTouch=webkit to the URL, all mouse-based interaction is hijacked and turned into touch events that the JavaScript in your web page can handle.

Simply add addTouch.js to your head element before any other javascript is included. Also add the addTouch.css stylesheet.

<html> <head> <script type="text/javascript" src="addTouch.js"></script> <!– Your other scripts here –> <link rel="stylesheet" type="text/css" href="addTouch.css"> </head> <body> <!– Your markup here –> </body> </html>

Here is a demo app:
Without addTouch – visit with iPhone or iPad
With addTouch – visit with any modern desktop browser

This version of addTouch only emulates the raw touchstart, touchmove and touchend events. You will not get any gesture* events. I will probably add gesture emulation in later versions. Also on the “to do” list is support for Mozilla-style touch events like MozTouchDown.

The addTouch project is available on github: /lbrtw/addTouch

Let me know what you think, and if this helps you. NB: addTouch supports pretty much any version of Chrome and Safari. I have only tested it in Firefox 4, but I would be surprised if it didn’t work in Firefox 3.6. For Internet Explorer, you’ll need a recent Platform Preview of IE9.

Happy 30th birthday Pac-Man, and also my career

The 30th anniversary of Pac-Man has come and gone, and so has the 30th anniversary of my introduction into the amazing world of computers.

A beginning

Back in 1980, I had just turned six, when my father bought a Sinclair ZX80. It wasn’t the first computer I had ever seen, though. My dad, a HAM radio enthusiast and an overall technology enthusiast, had already brought me to technology fairs and ham radio events. But the ZX80 was something special. It was our own computer!

We spent lots of time together, typing in program listings from (mostly British) computer magazines. The ZX80 only had 1kB of RAM (yes, that is 1024 bytes, actually including video RAM) and its BASIC interpreter fit snugly in its 4kB of ROM.

After about a year, we upgraded to the ZX81, with 8kB of ROM and a whopping 16kB of RAM. At the age of nine, I was helping my father teach BASIC programming on ZX Spectrums at the local workers’ educational association.

During those early years, I went through lots of different computers, including Spectravideo 728 MSX, Commodore Amiga 500, and Commodore Amiga 3000. I learned a few different programming languages, including PASCAL, C, C++, and assembly language for the Zilog Z80, and Motorola 680×0 series processors.

I started an Amiga demo group with a few of my high school friends, and learned that special flavor of assembler programming that was used in "the scene". I learned to love the algorithm. I got a good grasp on how compilers, optimizers and emulators work. I wrote a couple of small, but functional, operating systems. I cracked computer games and removed copy protection, just for the fun of analyzing and learning other people’s intricate assembly-coded secrets. But also for the secret guilty pleasure of knowing that I could do some things a little better than others.

Then, suddenly I turned eighteen.

Present day, eighteen years later

My thorough understanding of the inner workings of computers, that I developed as a child and a young adult, is still of great use and comfort for me. However, these days software development is not so much about saving clock cycles (even if that skill still does come in handy every now and then). When working with web-based solutions, service-oriented architecture, and huge integrations of large systems, it is sometimes important to be able to break a complex system down into its parts to get a better understanding of the whole. I am good at that.

I am thirty-six years old now. I still learn lots of new stuff, practically every day. I am still amazed when job applicants can’t write a simple Fizz-Buzz program in under five minutes! And I am still thankful to my father for bringing home the ZX80 thirty years ago.