How to prevent Chrome from changing text color when printing

Chrome has a feature that turns light text to black before printing. For instance, if you have a light gray paragraph on the page, it will print as black text.

While this feature might ensure that unoptimized pages are readable when printed, you might want to disable it so colors come out the way you intended.

To ensure that background images, background colors and text colors remain the same while printing, use the following CSS rule:

-webkit-print-color-adjust: exact

Office 2011 activation server unavailable? Here’s the fix

After almost a year after freshly installing MacOS, the time finally came for me to need the festering pile of ██ that is Microsoft Office 2011. Naturally, something was broken.

The activation screen refused to accept the license key I had used 5 minutes earlier to download the installer, stating that the activation server was temporarily unavailable.

The solution was to look for updates to Office 2011. After the latest update was installed, the key was accepted and my installation was activated. If that doesn’t work, you can always activate it by phone.

Fixing the “protocol error: bad pack header” error in git

When trying to push in git, you might get the following error message:

fatal: internal server error
remote: internal server error
fatal: protocol error: bad pack header

In my case, it was because I pulled a corrupted remote Gerrit repository, and tried to push the corrupted data back to the fixed remote. Everyone who had pulled the corrupted repository also ran into the same error.

Fortunately, the fix is really easy. All you have to do is run those four commands:

cp .git/config .git/config.backup
git remote remove origin
mv .git/config.backup .git/config
git fetch

This fix comes from Jordan Klassen.

Automatically tagging people for code review in Gerrit

If your gerrit workflow requires you to automatically tag people, or if you always end up tagging the same people, there is a way to tag people by default for all your commits.

To do so, edit .git/config to include the following lines and substitute the email with your colleague’s email:

[remote "origin"]
    ...
    receivepack = git receive-pack --reviewer "other.reviewer@company.com"

Fixing Jasmine “encountered a declaration exception”

If you ever come upon a Jasmine unit test that ends with “encountered a declaration exception”, it’s likely because you have committed a simple, subtle mistake. Every few weeks, I would get that error, and forgetting how I fixed it the previous time, spend another 30 minutes to fix it.

Here’s a screenshot of the Karma output:

enter image description here

Here’s the code that caused it:

describe('should be hidden when the scope is destroyed', () => {
  this.scope.$broadcast('$destroy');
  expect(this.scope.helpTooltip.hide).toHaveBeenCalledWith();
});

Can you spot the problem? It’s simple: I used describe instead of it. Let’s fix this…

it('should be hidden when the scope is destroyed', () => {
  this.scope.$broadcast('$destroy');
  expect(this.scope.helpTooltip.hide).toHaveBeenCalledWith();
});

Voilà! No more error! Sometimes, the solution is that simple.

How to improve Angular performance by disabling debugging

Angular JS

Angular gives elements classes such as ng-scope and ng-isolate-scope to help tools such as Batarang and Protractor retrieve debugging information. In production, these are unnecessary, and can be disabled to speed up your client-side application.

This is how you disable debugging information in Angular:

myApp.config(['$compileProvider', function ($compileProvider) {
  $compileProvider.debugInfoEnabled(false);
}]);

How to create static class constants in ES6

ES6 brings classes to JavaScript, but some things are not immediately obvious or entirely supported. For instance, there is no obvious way to create static class constants.

Here is the simplest way I have found to create constants:

class CurrentLocation {
  static get GEOLOCATION_ERROR() { return 'GEOLOCATION_ERROR'; }
  static get GEOLOCATION_REFUSED() { return 'GEOLOCATION_REFUSED'; }
  static get GEOLOCATION_ACQUIRED() { return 'GEOLOCATION_ACQUIRED'; }
  static get GEOLOCATION_PENDING() { return 'GEOLOCATION_PENDING'; }

  ...

  function isValid(){
    return this.status === CurrentLocationItem.GEOLOCATION_ACQUIRED
  }
}

In the example below, you can use CurrentLocation.GEOLOCATION_ERROR anywhere, but myGeolocationItem.GEOLOCATION_ERROR will not exist, as static members are not visible to class instances. Moreover, children of the CurrentLocation class will not inherit these attributes.

How to speed up apt-get on Digital Ocean

For some reason, downloading packages using apt-get install was unusually slow on DigitalOcean this week, barely exceeding 4kbps. Since DigitalOcean droplets are configured to download packages from mirrors.digitalocean.com, all I had to do was to revert them to the default Ubuntu sources using these two commands:

sudo sed -i "s/mirrors.digitalocean/archive\.ubuntu/g" /etc/apt/sources.list
sudo apt-get update

Downloads are now as fast as they should be.