1. TypeScript Type Guard

    In our code base, we have a utility function isArray to check whether an input is an Array. function isArray<T>(obj: any): boolean { return Array.isArray(obj); } Its goal is to return true if given input is an array, false if not. Other code references this utility…

  2. Jasmine async call

    I have been debugging this Jasmine spec: it(`should return tactic`, (done) => { source.updateTactic(1, { startDate: new Date(), endDate: new Date(), name: 'First Tactic', }).subscribe((response) => { expect(response).toEqual(updatedTacticJsonResponse); }); http.expectOne(`${BASE_URL}/v1/tactics/1`).flush(updatedTacticJsonResponse); }); with error message: Error: Timeout - Async…

  3. Test a component @Input binding in the form in Angular

    Angular component binds data through @Input, where data can be passed from parent to child (or from smart component to presentation component). It is basic Angular practice, but writing specs for presentation component could be tricky in some cases. In this example, smart component gets a form value from store,…

  4. Use block for loop in Ruby

    When we have a block of code that we'd like to loop through given numbers of times, we typically do (1..10).each # Run some code end Sometimes it's hard to document where the number 10 comes from and why. You certainly can do something like…

  5. SQL EXISTS vs JOINS

    EXISTS vs. JOINS pros and cons have been discussed over the time. I've seen some different arguments. Some say EXISTS is faster because when two joining tables are large, EXISTS reduces line joining by filter out unqualified rows. Some say they're about the same, because Postgres…

  6. Use Concerns in Rails

    When it comes that you need to reuse some functions across different models in Rails, Concern [http://api.rubyonrails.org/classes/ActiveSupport/Concern.html] comes to rescue. In our example, we have a few stats models which all have result_on field, which needs to be calculated from passed params…