Thursday, May 28, 2020

Enable remote desktop Windows 10 to Ubuntu 18.04


Steps:

Step 1:

Ubuntu.

Install next command on terminal:

sudo apt install xrdp

sudo systemctl enable xrdp

If you want check status, change enable to status or if you want disable type disable.


Step 2:

Windows 10.

Type on search: remote desktop.

Type your ip or hostaname on next windows:














When you click on connect automatically open next windows, type your username and password to remote desktop Ubuntu.

























Saturday, May 23, 2020

Kill port on Windows 10 by console


Open console with admin user.

Righ click on CMD open with administrador

Run next command:

netstat -ano | findstr :YOUR_PORT

Find PID and next

taskkill /PID YOUR_PID /F


Example:












Friday, May 22, 2020

Change dynamic value mat icon Angular 8 or greater


I share example how to change dynamic value mat icon with Angular.


Example, In my case, I want to change mat-icon expand_less to expand_more

HTML
 <button mat-icon-button color="primary">
   <mat-icon id="mat-{{name_dynamic_id}}" matTooltip="" aria-label="">
expand_less
</mat-icon>
 </button>

TS, Use native javascript.

Get Id.

var dynamicMatIccon = document.getElementById("mat-" + value);

Change value:

dynamicMatIccon.innerHTML = "expand_more";


That it is.


Monday, May 18, 2020

Linux tips

Number of files

 ls -l filename* | wc -l

Command to print directory structure 
ls -R MY_FOLDER | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//──/g' -e 's/─/├/' -e '$s/├/└/'

List only directories
ls -l | grep '^d'

Count total number of files in particular directory with specific extension.

ls -lR /path/to/dir/*.jpg | wc -l

Max thread, we can use. or number CPU.

lscpu


GREP

-Search multiple strings
grep '1\|2\|3' filename

-Number of lines with specific pattern search
grep -o 'STRING' filename | wc -l


SED
Replace values in file,
sed -i 's/old_string/new_string/' filename

With special character simple quotes
sed -i "s/old_string/'new_string'/g" filename

Add header string in the file.
sed -i '1s/^/addedtext\n/' filename

Add footer string in the file
echo "helloworld" | tee -a filename >/dev/null

Change extension filename in loop

for f in filename.txt;do mv $f  $f.sql;done

Split larger files into smaller parts 

-l number of lines

split -l 500000 filename

--bytes
K
M
G

Execute next the command on terminal example:

split --bytes=1G path/your_file.extension path/your_new_file.extension

Convert file UTF-8

iconv -f ISO-8859-1 -t UTF-8//TRANSLIT filein.txt > fileout.txt

Check special character on file 

grep --color='auto' -P -n "[\x80-\xFF]" file.txt

Could not get lock /var/lib/dpkg/lock-frontend - open

Delete the lock file:

sudo rm /var/lib/apt/lists/lock

Delete the lock file in the cache directory

sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

Generate RSA private and public key

Private key:

openssl genrsa -out private.pem 2048


Public Key from RSA private key:


openssl rsa -in private.pem -outform PEM -pubout -out public.pem

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!


Solution: run next command

ssh-keygen -R  YOUR_IP





Monday, April 20, 2020

Could not find acceptable representation .COM PathVariable Spring boot 2

Solution next error.

In your method RESTful web service add.


@GetMapping("/public/file/{url_filename:.*}")

And create next class.

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false).favorParameter(true);
}

}



Caused by: org.hibernate.AnnotationException: No identifier specified for entity

Solution next Error:

you need to add primary key in your table database and  add id(@Id) annotation attribute on your class in java.

Thursday, April 16, 2020

Can't serve static html with Spring Boot 2

Solution next error.

Add next class:

package your_package;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class StaticResourceConfiguration implements WebMvcConfigurer {

 private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
  "classpath:/META-INF/resources/",
  "classpath:/resources/",
  "classpath:/static/",
  "classpath:/public/"
 };

 @Override
 public void addResourceHandlers(ResourceHandlerRegistry registry) {
  registry.addResourceHandler("/**")
   .addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
 }

}


and try again access, for example:

http:localhost:8080/your_html.html

or

http:localhost:8080/your_context/your_html.html













References:
https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot







🔐AWS → Google Cloud Workload Identity Federation with Terraform

  Eliminating Service Account Keys for Cross-Cloud Workloads Managing identities across cloud providers is often more challenging than manag...