Skip to content

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.

Bootstrap 3 text-align (left/right) for xs, sm, md, lg screen sizes

02-Nov-18
/**
 * Text alignment for screen sizes
 */
 @media (max-width:767px){
   .xs-text-right {
     text-align: right;
   }
   .xs-text-left {
     text-align: left;
   }
 }
 @media (min-width:768px){
   .sm-text-right {
     text-align: right;
   }
   .sm-text-left {
     text-align: left;
   }
 }
 @media (min-width:992px){
   .md-text-right {
     text-align: right;
   }
   .md-text-left {
     text-align: left;
   }
 }
 @media (min-width:1200px){
   .lg-text-right {
     text-align: right;
   }
   .lg-text-left {
     text-align: left;
   }
 }

ESLint disable rule for the whole file: /* eslint-disable */

31-Oct-18

While rules can be disabled for a line with // eslint-disable-line [rule-name] the whole file disabling needs block comments: /* eslint-disable [rule-name] */