life is too short for a diary




Dear Vishi, daily logs for May 7, 2023

Tags: diary letters

Dear Vishi, this is my daily log for May 7, 2023.

Sleep

I am still having jetlag I guess. I sleep at 3 am and wake at 8 am. It's been almost a week. There is hilarious quote about sleep

"Dear sleep, I’m sorry we broke up this morning. I want you back!" — Anonymous

I like to collect quotes and keep a personal collection.

Passport from US Embassy

I had applied for dropbox stamping on May 1, 2023. I am still waiting for my passport. More than a week has passed. I made a foolhardy plan to only give 2 week buffer before boarding my flight. Hope the passport comes on time.

30 Days of LC Javascript challenge

There is a 30 day challenge hosted at leetcode.

Apply Transform Over Each Element in Array

Given an integer array arr and a mapping function fn, return a new array with a transformation applied to each element.

Input: arr = [1,2,3], fn = function plusone(n) { return n + 1; }
Output: [2,3,4]

The solution is straightforward to use map

var map = function(arr, fn) {
   return arr.map(fn);
};

Create Hello World Function

Write a function createHelloWorld. It should return a new function that always returns "Hello World".

Input: args = []
Output: "Hello World"

Solution:

var createHelloWorld = function() {
  return function(..args) {
    return "Hello World"
  }
}

Counter

Given an integer n, return a counter function. This counter function initially returns n and then returns 1 more than the previous value every subsequent time it is called (n, n + 1, n + 2, etc).


const counter = createCounter(10)
counter() // 10
counter() // 11
counter() // 12

Solution:

var createCounter = function(n) {
    return function() {
        return n++;
    };
};

This is a simple example of using closures in javascript.

  1. Closure are nested function which has access to the outer scope

  2. After the outer function is returned, by keeping a reference to the inner function (the closures) we prevent the outer scope to be destroyed.

SonarQube exclude directories

Sometimes you want to skip certain folders for scanning. Add following option to the config

-Dsonar.exclusions=**/site-packages/**

Top Gun movie

I watched it today. It was in my bucket list. I liked the soundtrack and visual effects. I guess story could have been more captivating.

ng-book

I am currenlty reading ng-book

Create a new project

$ ng new angular-hello-world

In the file angular-hello-world/src/index.html

<body>
<app-root> </app-root>
</body>

the app-root is where application is rendered. It's a component.

To run the application, go to localhost:4200

$ ng serve --port 4200

Create a component

$ ng generate component hello-world

Component consist of two parts

  1. a component decorator

  2. a component definition class

Open the file angular-hello-world/src/app/hello-world/hello-world.component.ts

import {Component, OnInit} from '@angualar/core';

@Component({
    selector: 'app-hello-world',
    templateUrl: './hello-world.component.html',
    styleUrl: ['./hello-world.component.css']
})

export class HelloWorldComponent implements OnInit{
  constructor() {}

  ngOnInit(){}
}

@Component is the decorators. In the angular-hello-world/src/app/app.component.html, we can use

<app-hello-world></app-hello-world>

I am tracking my books here


comments powered by Disqus