Category Archives: Uncategorized

Starting Stopping Kafka and ZooKeeper on Mac

Starting ZooKeeper

zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties

Start/Stop Kafka after starting up Zoo Keeper

kafka-server-start /usr/local/etc/kafka/server.properties

Creating Topic ‘Test’

open a terminal:

kafka-topics –create –zookeeper localhost:2181 -replication-factor 1 –partitions 1 –topic test

Creating Consumer

open a terminal:

kafka-console-consumer –bootstrap-server localhost:9092 –topic test –from-beginning

we wait for the producers to produce for topic ‘test’

Produce for our topic Test

kafka-console-producer –broker-list localhost:9092 –topic test

> haha
> hehe
> hoho

Now in your consumer terminal, you should see the texts come up

Nullish Coalescing

Is userInput null or undefined? NO. So don’t do anything.

Is userInput null or undefined? YES. So we result is assigned to ‘Default’.

Index Properties (typescript)

interface ErrorContainer {
[props: string]: string;
}

All I know is that every property which is added to this object must have a property name, which can be interpreted into a string, must contain a string.

i.e id: string;

i.e
const errorBag: ErrorContainer = {
email: “not a valid email”,
username: ‘Must start wiht capital character’
};

[props: number]

1: “hahahah”;

typescript (type guard)

Instead of using instanceof, or checking for an existing property, we create a discriminating union type.

Type Guard is the idea that a certain property exists

Type Guarding for types

Much better way is to use instanceof when trying to figure out what type the instance is. Because literally, instanceof is implemented to check if this particular instance is a type of something.

Discriminated Union

…helps with type guard.

3) discriminated Union types
can add type: ‘bird’, ‘horse’, then use switch animal.type in moveAnimal

Array Destructuring (JS)

Given,

We can destructure our array by placing the array elements into variables we create:

first sports
second cooking
remainingHobbies [‘sleeping’, ‘eating’]

typescript arrow function shorthand

const printOutput: (a:number|string) => void = output => console.log(output);

printOutput is the name of the function

(a:number|string) => void is the type. It says the function takes one parameter ‘a’ and the function returns void

output => console.log(output) is the body definition. We re-named a to output. then we console output

typescript debugging

download

Make sure your tsconfig looks like this:

In order to include comments, remember to put “removeComments”: false

Now we can code up our app.ts:

We included “dom” in our “lib” array in our tsconfig.json file. Thus, we can use document object. We declare a button handler and an add function. We

In the terminal:

tsc

to create app.js. This app.js is created inside a dist folder as indicated by outDir in our tsconfig.json.

Thus, in our index.html, we are able to use it:

After that start the server:

npm start

Then start the debugger

Run through the initialization breakpoints.

Test the button handler breakpoint.

typescript tsc

Install typescript (tsc) globally

You can use npm to install TypeScript globally, this means you can use the tsc command anywhere in your terminal.

To do this, run npm install -g typescript. This will install the latest version (currently 4.2).

Then verify:

ts init

Do this once. Will generate a tsconfig file.

Then all you have to do is tsc to compile all typescript files into js files for the directory.
You can also add watch to it: tsc -w