Skip to content

Instantly share code, notes, and snippets.

@diegohordi
diegohordi / ts
Created March 10, 2021 18:23
Detect screen size Angular
import {BreakpointObserver} from '@angular/cdk/layout';
...
breakpointObserver.observe(['(max-width: 1024px)']).subscribe(result => {
if (result.matches) {
this.responsiveVersion = true;
} else {
this.responsiveVersion = false;
}
});
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {MapInputComponent} from './components/map-input/map-input.component';
import {LeafletModule} from '@asymmetrik/ngx-leaflet';
@NgModule({
declarations: [MapInputComponent],
imports: [
CommonModule,
{
...
"styles": [
"src/styles.scss",
"./node_modules/leaflet/dist/leaflet.css"
],
...
}
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {AppComponent} from './app.component';
import {LocationService} from './services/location.service';
import {HttpClientModule} from '@angular/common/http';
@NgModule({
declarations: [
AppComponent
],
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {LatLng} from 'leaflet';
@Injectable({
providedIn: 'root'
})
export class LocationService {
@diegohordi
diegohordi / app.module.ts
Last active March 3, 2020 10:27
Map Input
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {AppComponent} from './app.component';
import {LeafletModule} from '@asymmetrik/ngx-leaflet';
import {LocationService} from './services/location.service';
import {HttpClientModule} from '@angular/common/http';
@NgModule({
declarations: [
AppComponent
@diegohordi
diegohordi / georadius-checker.go
Created January 24, 2020 10:31
Writing and deploying your first AWS Lambda
package main
import (
"context"
"github.com/aws/aws-lambda-go/lambda"
"math"
)
...
@diegohordi
diegohordi / georadius-checker.go
Last active January 24, 2020 12:03
Check radius AWS Lambda
...
func HandleRequest(ctx context.Context, coordinates Coordinates) (Result, error) {
result := Result{InsideRadius: IsInsideRadius(coordinates.ALatitude, coordinates.ALongitude, coordinates.BLatitude, coordinates.BLongitude, coordinates.Radius)}
return result, nil
}
func main() {
lambda.Start(HandleRequest)
}
@diegohordi
diegohordi / georadius-checker.go
Last active January 22, 2020 00:09
Check radius AWS Lambda
...
func IsInsideRadius(aLatitude float64, aLongitude float64, bLatitude float64, bLongitude float64, radius int) bool {
diffLongitudeRadians := toRadians(bLongitude - aLongitude)
aLatitudeRadians := toRadians(aLatitude)
bLatitudeRadians := toRadians(bLatitude)
difference := math.Acos(math.Sin(aLatitudeRadians)*math.Sin(bLatitudeRadians)+math.Cos(aLatitudeRadians)*math.Cos(bLatitudeRadians)*math.Cos(diffLongitudeRadians)) * slcRadius
return difference <= float64(radius)
}
...
@diegohordi
diegohordi / georadius-checker.go
Last active January 21, 2020 23:44
Check radius AWS Lambda
...
func toRadians(degrees float64) float64{
return degrees * math.Pi/180
}
...