vrijdag 31 maart 2023

Latlon afstand per eenheid berekenen

import geopy.distance

coords_1 = (53.219379, 6.575347)
coords_2 = (53.219396, 6.575226)

print(geopy.distance.geodesic(coords_1, coords_2).km)

Ouput: 0,008300847602651781 km


Distance in eenheid berekenen:
        public double DistanceBetween(Vector v1, Vector v2)
        {
            Vector diff = v2 - v1;

            var distance = Math.Sqrt((diff.Longitude * diff.Longitude) + (diff.Latitude * diff.Latitude));
            return distance;
        }

Ouput: 0,0001221883791528447 eenheid

Dus 1 eenheid = 67,93483685 km.
Dus 0,001 eenheid per seconde = 67,93483685 m/s * 60 * 60 = 245 km/h
1 km/h = 0,001 / 245 = 0,0000040888856
100 km/h = 0,00040888856

maandag 20 maart 2023

Postgresql version and extensions that are installed

To see the PostgreSQL version number:
select version();

To see which extensions are present:
select * from pg_extension;

zaterdag 4 maart 2023

rxjs

Rxjs is a great library for declarative programming. The main advantage of declarative programming, in my opinion, is the fact that related code is together glued in one place.

For instance, I wanted to buffer incoming messages and have them emitted every second. That was easy in Rxjs.

Angular:

public originalStream$: Subject<SpecificObj> = new Subject<SpecificObj>();
public bufferedStream$: Observable<SpecificObj[]> = this.originalStream$.pipe(bufferTime(500), filter(arr => arr.length >0));

in the init:
this.bufferedStream$.subscribe((values: SpecificObj[]) => {
for (let newObj of values) {
}
});
in the code: originalStream$.next(obj); Example pure javascript: let container = $(document.body);
function log(val) {
container.append(`<div>${val}</div>`);
}

const { of, interval } = rxjs;

//const stream = of(1,2,3,4);
const stream = interval(1000);

stream.subscribe(val => log(val));

https://dev.to/hssanbzlm/building-autocomplete-feature-rxjs-with-vanilla-javascript-c7
https://rxjs.dev/guide/overview
https://eliteionic.com/tutorials/imperative-vs-declarative-programming-with-rxjs-search-filter/#a-declarative-search-filter
https://lodash.com/
https://johnlindquist.com/rxjs-pipes/