Logo Subtitle Subtitle

Using Google Dart as an online collaboration calculator

When I’m stuck on math questions I turn to my friend chris who can write pixel perfect C# code in a chat window. Yesterday I needed to calculate where a line intersects a circle so after a few google searches I came up with this Google Dart code:

double x1=100.0;
double y1=100.0;
double x2=200.0;
double y2=200.0;
double radians=Math.atan2(y2-y1, x2-x1) ;
double radius=50.0;
double y3=y2+radius * Math.cos(radians);
double x3=x2+radius * Math.sin(radians);

As it turned out, I made two mistakes. The last two lines should be:

double y3=y1+radius * Math.sin(radians);
double x3=x1+radius * Math.cos(radians);

How did I find out? Easy! I entered the code in the Dart editor and sent the generated link to Chris. He looked at the code, made some changes and sent a link back.

Calculate intersection point of line and circle

I wrote this post to point out the power of a shared code editor and to show how to calculate where a line intersects a circle. Open the link in a recent Chrome or Firefox browser and press play!

Class and property in the Google Dart language

Today I played with the new Google Dart language and I liked what I saw. Google calls it “Structured Web Programming” and it’s purpose is replacing Javascript as the primary scripting language in browsers.

One of the things I really miss in Javascript are proper classes. You can fake classes with functions but it is what it is. Not a Class (NaC). So in my example I rebuilt a C# class that we use a lot in our Silverlight training: ‘Employee’

The Employee class has a constructor that takes a Name (string) and Salary (double). It has a method RaiseSalary(double percentage) and a public property ‘Info’ that returns info about the employee.

Getting started

So let’s start by opening http://try-dart-lang.appspot.com/ in Chrome. I use Chrome 14.0.835.202.

Dart code

Let’s start with a main top level function main function:

main() {
  print('Hello, Vera!');
}

Enter the code in the Dart editor and press the play button:

Employee class

So here’s an example of a class with a public property in Google Dart:

class Employee{
  String name;
  double salary;

  Employee(String name, double salary){
    this.name=name;
    this.salary=salary;
  }

  get Info()=> "Hello "+name+", your salary is €"+salary;

  RaiseSalary(double percentage){
    salary=salary+salary*percentage/100;
  }
}

Create and use this class like this:

main() {
 var emp=new Employee("Vera",4500.0);
 print(emp.Info);
 emp.RaiseSalary(6);
 print(emp.Info);
}

Wich results in:

This is just a small example but it’s a nice start with Dart. You can find the full Language specification on the Dart website. Happy coding!

Find unused resources in Silverlight or WPF with ResourceCounter

I am currently working on a very interesting Silverlight Project for Philips Healthcare. Like all projects it is rapidly growing and it’s time for some cleaning up.

When you use Expression blend it’s easy to create static resources for everything you are going to re-use. Static resources are always loaded in Silverlight. Even if they are not used. Unfortunately Expression Blend does not have a way to get rid of unused resources. Last year I built a small WPF app that analyses your project for you and indicates unused static resources. I’ve used it again today and decided to share it with you.

ResourceCounter

Download and extract ResourceCounter.zip and run the exe.
Enter a valid path to a Silverlight or WPF project and click ‘Analyse’

Icons or other visuals with XAML instead of bitmaps

You want to use vector images in your Silverlight project instead of bitmaps? In this tutorial I’ll show you how.

Buttons with vector images

Start Expression Blend and place a button on the Grid.


When u use a *.PNG icon, you can drag this on the button. But we are going to draw a little magnifying glass icon with Expression Blend. Rightclick the button in the Objects and Timeline tab and choose: Edit Additional Templates | Edit generated Content | Create Empty…

Choose a name and hit OK

A DataTemplate resource has been created in the UserControl.Resources collection. Draw an ellipse and a rectangle to create the search icon (or be more creative :-)

And that’s it! Apply this datatemplate to the ContentTemplate of other buttons to re-use the vector drawing:

This resource was created in the UserControl (MainPage.xaml). It’s a better idea to create the resource in a separate resource file like Visuals.xaml but that depends on your preferences.

Mac OS Lion keystrokes for me myself and I

This blogpost is just a reminder to myself to use the following keystrokes. What are you still doing here? ;-)

Action Keystroke
Shutdown without questions ctrl+alt+cmd+eject
Sleep without questions alt+cmd+eject
Quit frontmost application hold shift+alt+cmd+esc
Screenshot of selected area shift+alt+4
Insert Euro symbol shift+alt+2