Skip to content

An Adult, Who? (Be Clear, Be Specific)

16-Jun-20

Buying plane tickets for adults and children. But starting from 12 years, what category does a person belong to?

vs.

When your industry's conception of a word is different from general usage, be specific and open about it.

CSS :hover on Touch Screens

09-Jun-20

Use:

@media(hover: hover) and (pointer: fine) {}

Spec not finalized, but so far so good.

Source: https://medium.com/@mezoistvan/finally-a-css-only-solution-to-hover-on-touchscreens-c498af39c31c

Git: When to Close (Delete) Branch after PR

15-Jan-19

When should I close (i.e. delete) the branch after a successful pull request? Rule of thumb: always. (There are exceptions of course.)

What if I need to recover the deleted work? You'll just

git checkout -b <branch> <sha>

 

Jasmine unit tests throwing "Possibly unhandled rejection" with Angular 1.6?

09-Nov-18

Each $q.reject() throws an error if not being chained properly. First check that all calls have a .catch(). Second, if possible, isolate your error cases to an independent describe block. Example below using bardjs, but the idea should be clear enough.

  let stuffDataservice;
  const stuff = [{}]; 

  beforeEach(function() {

    [...]

    stuffDataservice = {
      getStuff: function () { return $q.when(stuff); },
      getSomethingElse: function () { return $q.when(somethingElse); }
    });

    scope = $rootScope.$new();

    controller = $controller('MyController', {
      $scope: scope,
      stuffDataservice: stuffDataservice
    });

  });
  describe('.getStuff()', function() {

    it('gets stuff', function() {
      scope.$apply();
      expect(controller.stuff).toBe(stuff);
    });

    describe('failure', function() {

      let failingController;

      beforeEach(function() {
        /* overrides previously defined $q.when */
        stuffDataservice.getStuff = function() {
          return $q.reject();
        };
        /* new controller needed to make use of changes in dataservice */
        failingController = $controller('MyController', {
          $scope: scope
        });
      });

      it('is handled', function() {
        scope.$apply();
        expect(failingController.variableDescribingTheFailure).toBeDefined();
      });

    });

JavaScript: get domain from url with JS regex

07-Nov-18

It's as simple as url.match(/\/\/(.[^/]+)/)[1]. Requires the double slash before the domain part, but not a slash after it.