AngularJS $q: Creating an already resolved promise

Just a brief note, because I found that nowhere on the web (at least not with my search terms).

Sometimes you want to create a promise, where you already know the result. For example when you only need an asynchronous operation in some cases:

function downloadItems(keys) {
  if(keys.length > 0){
    return $http({method: 'GET', url: constructUrl(keys)}); // a promise.
  } else {
        // TODO: return an empty array, but in a promise.
  }
}

My first approach was to create a deferred, resolve it and return its promise:

  var deferred = $q.defer();
  deferred.resolve([]);
  return deferred.promise;

Realizing that this is a task you do very often, I searched for a better solution. After an unreasonable amount of time, I finally found it:

  return $q.when([]);

(http://stackoverflow.com/questions/16770821/how-does-angular-q-when-work)

Of course this is not part of the AngularJS documentation, as the documentation is really minimal when it comes to the $q service.

, , ,

2 Comments

Keepass Setup with Google Drive (for the paranoid)

Citadel of Pamplona

I used the time over christmas to setup Keepass to sync across different devices. I cannot live my digital life without a password manager anymore – now that I started to use one password per service. And besides that it also offered a nice excuse to play with my new Nexus 5 🙂

Before I didn’t want to upload my password db to a cloud service because I didn’t really trust my password. It certainly isn’t a simple one – more than 12 characters long and with different character classes – but it’s probably still not completely secure. Then I found out that Keepass also supports key files (in addition to the password). This lets you easily add more random bits to crack in order to open the key file – without having to type an extremely long password.

So here’s my setup:

Phone

  • Keepass2Android (the online version) Note: This app rocks! In case you’re still using KeePassDroid have a look at it…
  • The keyfile (on the local storage)
  • the password DB (on Google drive)

Computers

  • Keepass
  • The keyfile (again only locally)
  • Google Drive
  • the password DB (on Google drive). I just open the File from the Google Drive folder using Keypass – syncing works quite nicely in the background without any special treatment.

As I only have a few devices where I want to access my passwords, setting up the keyfile on that device is not a problem.

So now I have the mix of security and comfort for my personal needs. Well I consider it secure at least unless any of the devices I use is compromised and as long as I trust Android, Keepass, Keepass2Android and Windows. Ok… maybe I’m just not paranoid enough.

, , ,

2 Comments

EGit: Compare local with remote branch before pushing

After working for a few days on a branch,  I was just about to merge the changes back to the master branch. Fortunately I regularly rebased the branch, so there were no merge conflicts.

But before pushing the changes into origin/master I wanted to show all the pending changes to a colleague. And I wanted to show it inside Eclipse to ease lookup of code related to the changes. I was trying to find that functionality in Team Synchronization perspective – without success. Fortunately EGit provides the functionality nonetheless:

 

Here’s how you can do it:

  •  Right click on the root of your project
  • “Compare With”/ “Branch, Tag or Reference… “
  • Select “Remote Tracking”, “origin/master”
  • “Compare”
  • voilà – there you have the changes in Eclipse Team Synchronizing View.

BTW if you just want to see all the changes in your difftool of choice, you could also use

git difftool --dir-diff --stat origin/master

1 Comment

Visual Studio: Profiling Applications with signed dlls

If you’re trying to profile an application with signed DLL’s in Visual Studio 2012 using instrumentation, you first see a warning and then you’ll probably see a System.Security.SecurityException complaining about “Strong name validation failed”.

Stackoverflow ([1]) suggests to run the following command to disable strong name validation on your computer:


sn -Vr *

Note: Please think about the security issues related to disabling strong name validation! (also described in the stackoverflow answer)

Unfortunately this command didn’t seem to work for me (Win 7 64-bit, VS 2012 32-bit, with an “64 bit” application to profile).

Luckily i found a blog post [3] writing about the registry keys that sn.exe creates behind the scenes. Even though the blog post describes ways to get 32-bit working, my problems were related to missing keys for 64-bit application. Strangely Sn.exe didn’t create the keys at all.

Long story short, I added the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\StrongName\Verification\*,*

And I was finally able to profile my application!

References

[1] http://stackoverflow.com/questions/2711484/vs-2010-profiling-problem-with-signed-assemblies
[2] http://blog.icloneable.com/2010/12/strong-name-validation-failed-on-64bit.html
[3] http://blogs.msdn.com/b/shitals/archive/2008/05/01/8446582.aspx

, ,

Leave a comment

Teaching Software Development Apprentices

Apprenticeship

One of the things I like about my new employer is that we’re educating apprentices here (explanation of the swiss education system). Because the former supervisor of the apprentices will start studying, I have the honor of coaching the apprentices from now on.

How to Focus on the most important Aspects?

Currently there are two apprentices that are working here, both in the second year of their apprenticeship that takes four years. As you can guess they still have a lot to learn, but what are the most important points to teach? Where do I need to be picky and which points could I neglect for the moment?

There are a thousand things that are important to me while developing, but it doesn’t make sense to throw all at them while they’re still struggling with the basics. So I decided to make a list of main points that I want to focus on. But this turned out to be quite hard, again a thousand things came to my mind.

Vision to the Rescue!

Suddenly, I had an idea. If this were a project and I had problems to focus on the most important aspects, what could be the cause? Yes, I was clearly missing a vision of what I want the apprentices to achieve until the end of their apprenticeships.

So what is the apprenticeship all about?

My Vision

I want our apprentices to be valuable team members in development projects by the end of their apprenticeship.

A common Goal

Having a vision about where to head with the apprentices is a nice idea, but in the end they need to share my vision. So I talked with them to find out where they see themselves in two years. Luckily they both want to stay in development and – also important –  want work in development teams.

What’s next?

Now that the vision is clear I want to find out which skill I want to teach. Some of them will be foundation skills like

  • precision
  • problem solving
  • reliability

Then there are of course many development-related skills:

  • Logic and basic coding
  • Design from code level until component level
  • Testing
  • Refactoring
  • Patterns
  • Awareness for architecture

This lists are far from being complete, but it is already too much to pay attention to all of them at the same time. So as a next step I will put them in the rough order in which I want to teach them.

,

1 Comment

Don’t Idle While Your Test Suite Is Running

Whenever developing you’ll have occasions with some time to kill. For me this is usually shortly before I check in non-trivial stuff. Why? because this means I’ll run the complete test suite of the project which usually takes a few minutes.

Once after catching myself browsing through random news – again – I decided to think about what I’d better be doing while waiting. So here’s my list:

  • Read through all modifications you made. Are you _really_ ready to check in?
  • Check the Javadoc/XmlDoc of the modified parts – is all up to date?
  • Think about what you need to do next (and how you want to get there)
  • Have a look at the execution times of the previous test run. How could you speed up the slowest test?

What do you do while waiting?

,

Leave a comment

Setting up OpenLDAP on Ubuntu

Setting up ldap on Ubuntu isn’t hard – you just need to know how to do it.

sudo apt-get install slapd ldap-utils

You’re only asked for the administrator password, but you can’t configure the domain and organization. The easiest way to do this initial configuration of your ldap ist to do a dpkg-reconfigure.

sudo dpkg-reconfigure slapd

If you want a simple web UI to do the rest of the ldap configuration you might want to use phpldapadmin:

sudo apt-get install apache2 php5 phpldapadmin

Before you login, reconfigure the phpldapadmin – configuration. Edit these two lines to match your configuration:

$servers->setValue('server','base',array('dc=example,dc=com'));
$servers->setValue('login','bind_id','cn=admin,dc=example,dc=com');

If you’re unsure what values might fit, have a look at

/etc/ldap/slapd.d/cn=config/olcDatabase={1}hdb.ldif

Now you’re ready to login to http://localhost/phpldapadmin and configure your ldap – good luck 🙂

,

Leave a comment

Delegation in Scala

Something that just came to my mind – shouldn’t it be easier to do delegation in Scala than in Java? Of course it is.;)

class Delegate {
	def doit(i: Int, s: String){
		println(s + " : " + i)
	}
}

class Delegating {
  val delegate = new Delegate
  def doitToo = delegate.doit(_,_)
}

Even though it is probably in most cases better to define the type of “doItToo” – otherwise changes in class Delegate would break the clients of class Delegating. To be honest, the advantages over Java are not that big anymore:

class Delegating2{
  val delegate = new Delegate
  def doitToo(i: Int, s: String) = delegate.doit(_,_)
}

But this is not so much of an issue if you’re just implementing an interface.

trait Doer{
def doit(i: Int, s: String)
}

class Delegating3 extends Doer{
val delegate = new Delegate
def doit = delegate.doit(_,_)
}

You see, there are some slight advantages even with delegation.

One last thing: because Scala’s traits let you implement default behaviour in traits, you’ll probably delegate less often anyway.

Leave a comment

Erster Test mit Sourcen…

Scala:


class Point(val x: Int, val y: Int){
  def toString():String = "(" + x + ", " + y + ")"
}

Java:


class Point{
  public final Integer x;

  public final Integer y;

  public Point(int x, int x){
    this.x = x;
    this.y = y;
  }

  public String toString(){
    return "(" + x + ", " + y + ")";
  }
}

Leave a comment