marioosh.net

mini blog / notes

Docker – inspect running container

List running containers $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ec7ad9e8d7a5 spring-demo "java -jar /app.war" 3 minutes ago Up 3 minutes nifty_boyd$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ec7ad9e8d7a5 spring-demo "java -jar /app.war" 3 minutes ago Up 3 minutes nifty_boyd Go inside running container and run command Read more about Docker – inspect running container[…]

SQL: UPDATE by SELECT

Need update t_reports table, column tanked_sum. t_reports – reports table – tanked_sum – sum of tanked from t_vehicles table t_vehicles – vehicles table (more than one vehicle is in one report) – tanked – refueled liters of fuel for one vehicle — select only (count in `tanked_sum_counted` column) SELECT tanked_sum_counted, * FROM t_reports r JOIN ( SELECT Read more about SQL: UPDATE by SELECT[…]

@Optional dependency in Angular

Usage of @Optional (optional dependency), for example when LoginComponent is used as dialog or standalone. import { Optional } from ‘@angular/core’;   constructor( @Optional() private dialogRef: MatDialogRef<LoginComponent>, ) { … } import { Optional } from ‘@angular/core’; constructor( @Optional() private dialogRef: MatDialogRef<LoginComponent>, ) { … }

Reactive Form: previous value

let form = this.fb.group({ ‘hotelLocation’:[null] });   form.get(’hotelLocation’).valueChanges.subscribe(v => {   // HERE !! let prevVal = this.form.value[’hotelLocation’]; });let form = this.fb.group({ ‘hotelLocation’:[null] }); form.get(‘hotelLocation’).valueChanges.subscribe(v => { // HERE !! let prevVal = this.form.value[‘hotelLocation’]; });

@DateTimeFormat usage example

@GetMapping("/find") public Page<ReportProjection> reports( @RequestParam(required = false, name = "status") ReportStatus status, @RequestParam(required = false, name = "search") String search, @DateTimeFormat(pattern="yyyy-MM-dd") @RequestParam(required = false, name = "from") Date from, @DateTimeFormat(pattern="yyyy-MM-dd") @RequestParam(required = false, name = "to") Date to, Pageable pageable) { return reportService.reports(status, search, from, to, pageable); }@GetMapping("/find") public Page<ReportProjection> reports( @RequestParam(required = false, name Read more about @DateTimeFormat usage example[…]

List to Map (streams)

@Getter @Setter class Directory { Long id; String name; }   List<Directory> l = repo.allDirectories();   Map<Long, String> m = l.stream() .collect(Collectors.toMap(d -> d.getId(), d -> d.getName()));@Getter @Setter class Directory { Long id; String name; } List<Directory> l = repo.allDirectories(); Map<Long, String> m = l.stream() .collect(Collectors.toMap(d -> d.getId(), d -> d.getName()));

@PreAuthorize and SpEL params

If @PreAuthorize is used on interface, parameter name (id) in SpEL must match parameter name in implementation (not required on interface – fileId). @Transactional public interface FileService {   @PreAuthorize("@securityService.canAccessFile(#id)") File getFile(Long fileId); }   /** * GOOD */ @Service public class FileServiceImpl implements FileService {   @Override public File getFile(Long id) { /* … Read more about @PreAuthorize and SpEL params[…]

Required @Input

selector: ‘app-test[id]‘ Component({ selector: ‘app-test[id]’ // id is required now }); export class TestComponent { @Input() id:number; }Component({ selector: ‘app-test[id]’ // id is required now }); export class TestComponent { @Input() id:number; }