Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Banujan Balendrakumar banujan6

🏠
Working from home
View GitHub Profile
View medium-rxjs-scheduler.js
import { Observable, asyncScheduler } from 'rxjs';
import { observeOn } from 'rxjs/operators';
// "asyncScheduler" is a type of Scheduler which executes the Observable Asynchronously.
// "observeOn" is a Pipeable Operator that help us to re-emit the data with Scheduler.
const observable = new Observable((observer) => {
observer.next("First Data");
observer.next("Second Data");
observer.next("Third Data");
@banujan6
banujan6 / medium-rxjs-operators-creation.js
Last active Sep 5, 2021
medium-rxjs-operators-creation
View medium-rxjs-operators-creation.js
import { of } from 'rxjs';
// of is a Creation Operator,
// That can create new Observable by taking the parameters as the emitting values.
of("First Data", "Second Data")
.subscribe(data => console.log(data));
// CONSOLE OUTPUT ------------------------
// > First Data
View medium-rxjs-operators-pipeable.js
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
// Create a Observable which emits 2 values
const observable = new Observable(subscriber => {
subscriber.next('First Message');
subscriber.next('Second Message');
});
// "first()" is a pipeable operator that only returns the observable with the first value.
@banujan6
banujan6 / medium-rxjs-subject-vs-observable.js
Last active Sep 5, 2021
medium-rxjs-subject-vs-observable
View medium-rxjs-subject-vs-observable.js
import { Subject, Observable } from 'rxjs';
const observable = new Observable(subscriber => {
subscriber.next(Math.random()); // passing a random number
})
// Gives 2 different number. Because Observables are unicast and it will be execute separatly for each subscription.
observable.subscribe(data => {
console.log('subscription a :', data); //subscription a :0.2859800202682865
View medium-rxjs-subjects.js
import { Subject } from 'rxjs';
const subject = new Subject();
subject.subscribe({
next: (v) => console.log(`observerA: ${v}`)
});
subject.subscribe({
next: (v) => console.log(`observerB: ${v}`)
});
View medium-rxjs-subscription-1.js
/**
First Example
**/
import { Observable } from 'rxjs';
// Observable Object
const observable = new Observable(subscriber => {
subscriber.next("First Message");
@banujan6
banujan6 / medium-rxjs-observer.js
Last active Sep 4, 2021
Medium-RXjs-observer
View medium-rxjs-observer.js
// Simple Observer Object
const observer = {
next(data) {
console.log('We Received new data ' + data);
},
error(err) {
console.error('Oh, No. We got an error : ' + err);
},
complete() {
View medium-rxjs-observable.js
import { Observable } from 'rxjs';
const observable = new Observable(subscriber => {
subscriber.next("First State / Data of Observable"); // Notifiying first state
subscriber.next("Second State / Data of Observable"); // Notifiying second state
subscriber.next("Third State / Data of Observable"); // Notifiying third state
// Just waiting 5 seconds
@banujan6
banujan6 / home.component.html
Created Jun 13, 2021
azure cognitive services + angular
View home.component.html
<div class="container">
<div style="padding-bottom: 40px;" *ngIf="imageRawString !== null">
<div
class="object-marker"
*ngFor="let objectData of objects"
[ngStyle]="{
'margin-left.px': objectData.rectangle.x / image.ratio,
'margin-top.px': objectData.rectangle.y / image.ratio,
'width.px': objectData.rectangle.w / image.ratio,
'height.px': objectData.rectangle.h / image.ratio