rxjs: switchMap and switchMapTo

 https://stackoverflow.com/questions/39108549/switchmapto-creates-observable-before-subscription

It is calling early because you are calling the function when you are building the stream.


switchMap takes a function which gets invoked when a new value comes from up stream. The result of that function is subscribed to as a new stream.


switchMapTo takes an Observable which is subscribed to for every value that comes from up stream. You are creating the Observable by invoking getTestStartTime$().


Use switchMap when the output depends on the value coming from upstream, and use switchMapTo when the actual upstream value is irrelevant and is only used as a signal for subscription.


Getting To Know The Partial Type in TypeScript

 https://netbasal.com/getting-to-know-the-partial-type-in-typescript-ecfcfbc87cb6

I don’t usually bother to write about such small things, but I’ve come across many people who don’t know this handy feature, so I decided I should.

Let’s say we have a UserModel interface:

interface UserModel {
email: string;
password: string;
address: string;
phone: string;
}

And a User class with update() method:

class User {
update( user: UserModel ) {
// Update user
}
}

The problem with the code above is that we must pass an object that implements the whole UserModel interface, otherwise typescript will be 😡.

But in our case, we want to be dynamic and not be committed to the entire interface, but still get IntelliSense.

TypeScript (v2.1) provides us with a solution precisely for these cases — The Partial interface. All we need to do is to change the code above to this:

class User {
update( user: Partial<UserModel> ) {
// Update user
}
}

Now we can have the best of both worlds.

Another useful example would be if you have a component that takes configuration object as Input() and you want to have a default value.

type ComponentConfig = {
optionOne: string;
optionTwo: string;
optionThree: string;
}
export class SomeComponent { private _defaultConfig: Partial<ComponentConfig> = {
optionOne: '...'
}
@Input() config: ComponentConfig;

ngOnInit() {
const merged = { ...this._defaultConfig, ...this.config };
}
}

Under the hood the Partial interface looks like this:

type Partial<T> = { [P in keyof T]?: T[P]; };

You can read more about the keyof feature here.

https://stackoverflow.com/questions/54986332/typescript-class-extending-partial-interface


The problem is that Partial<T> will only allow you to implement the members will not require you to do so, and if you don't implement the member it will not be in the class.

You can create a function that returns a class and this class will implement the interface. The returned class will not actually have to declare any of the fields so they will all be undefined but this should be fine since the fields have to be optional anyway.

interface Animal {
    name: string;
}

type OptionalAnimal = Partial<Animal>;
function autoImplement<T>(): new () => T {
    return class { } as any;
}
class Dog extends autoImplement<OptionalAnimal>() {
    public constructor() {
        super();
    }
    public breed: string;
}

var spot = new Dog();

spot.name = "Spot"; // ok now

You can also cast the Dog class to specify that the returned instance has the members of Animal but these new members will not be accessible from inside the class:

interface Animal {
    name: string;
}

class _Dog {
    public constructor() {

    }
    public breed: string;
}

const Dog = _Dog as { new(): _Dog & Partial<Animal> } & typeof _Dog
type Dog = InstanceType<typeof Dog>

var spot = new Dog();

spot.name = "Spot"; 

How To Rename a Local and Remote Git Branch

 Source: https://linuxize.com/post/how-to-rename-local-and-remote-git-branch/


You are collaborating on a project with a group of people, and you have defined a naming convention for git branches. You created a new branch , pushed the changes to the remote repository, and realized that your branch name was incorrect.

Luckily, Git allows you to rename the branch very easily using the git branch -m command.

This guide explains how to rename local and remote Git branches.

Renaming Git Branch

Follow the steps below to rename a Local and Remote Git Branch:

  1. Start by switching to the local branch which you want to rename:

    git checkout <old_name>
  2. Rename the local branch by typing:

    git branch -m <new_name>

    At this point, you have renamed the local branch.

    If you’ve already pushed the <old_name> branch to the remote repository , perform the next steps to rename the remote branch.

  3. Push the <new_name> local branch and reset the upstream branch:

    git push origin -u <new_name>
  4. Delete the <old_name> remote branch:

    git push origin --delete <old_name>

That’s it. You have successfully renamed the local and remote Git branch

`npm build` doesn't run the script named “build” in package.json

 Source: https://stackoverflow.com/questions/29939697/npm-build-doesnt-run-the-script-named-build-in-package-json


Unfortunately npm build is already an internal command, as described in the docs:

This is the plumbing command called by npm link and npm install. It should generally not be called directly.

Because that command already exists, it always shadows over your "build": "node build.js".

The fully-qualified way to run your own script is with run-script or its alias run:

$ npm run build

npm start and others are the short-hand way, but is only an option when an existing npm command doesn't shadow it, like npm build does.


For posterity (as others have mentioned) npm build is used by npm to build native C/C++ Node addons using node-gyp. It's not documented well because usually it happens automatically, but if you're interested the source code is here.

How to access class variable inside Promise then() function?

 https://stackoverflow.com/questions/48064389/how-to-access-class-variable-inside-promise-then-function

If you pass a function reference, this won't point to the local class instance anymore.

You can use bind

.then(this.extractData.bind(this))

or arrow functions

.then((res) => this.extractData(res))

to get the desired behavior.

'wmic' is not recognized as an internal or external command, operable program or batch file

 https://superuser.com/questions/1178674/wmic-is-not-recognized-as-an-internal-or-external-command-operable-program-or


This indicates that the wmic utility's directory is not found on your PATH. Open the advanced System Properties window (you can open the System page with Windows+Pause/Break) and on the Advanced tab, click Environment Variables. In the section for system variables, find PATH (or any capitalization thereof). Add this entry to it:

%SystemRoot%\System32\Wbem

Note that entries are delimited by semicolons.

How to completely remove node.js from Windows

 https://stackoverflow.com/questions/20711240/how-to-completely-remove-node-js-from-windows

How to remove Node.js from Windows:

  1. Take a deep breath.

  2. Run npm cache clean --force

  3. Uninstall from Programs & Features with the uninstaller.

  4. Reboot (or you probably can get away with killing all node-related processes from Task Manager).

  5. Look for these folders and remove them (and their contents) if any still exist. Depending on the version you installed, UAC settings, and CPU architecture, these may or may not exist:

    • C:\Program Files (x86)\Nodejs
    • C:\Program Files\Nodejs
    • C:\Users\{User}\AppData\Roaming\npm (or %appdata%\npm)
    • C:\Users\{User}\AppData\Roaming\npm-cache (or %appdata%\npm-cache)
    • C:\Users\{User}\.npmrc (and possibly check for that without the . prefix too)
    • C:\Users\{User}\AppData\Local\Temp\npm-*
  6. Check your %PATH% environment variable to ensure no references to Nodejs or npm exist.

  7. If it's still not uninstalled, type where node at the command prompt and you'll see where it resides -- delete that (and probably the parent directory) too.

  8. Reboot, for good measure.

Cold Turkey Blocker

 https://superuser.com/questions/1366153/how-to-get-rid-of-cold-turkey-website-blocker-get-around-the-block Very old question, but still wan...