install redis docker on windows 10 and run

I am using docker desktop on windows 10 machine. I used the following commands to run Redis and used them in my application for Redis connection.

docker pull redis
docker run -p 6379:6379 --name some-redis -d redis

Following the code will help you. If Redis running properly.

you can go into Redis docker-machine.

docker exec -it some-redis /bin/bash

redis-cli ping

windows 10 kill port 8080

When I tried to start spring boot application I got the following error

Web server failed to start. Port 8080 was already in use.

Action:

Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port.

Solution:

I executed following commands for kill 8080 port

>netstat -ano | findstr :

(Replace with the port number you want, but keep the colon)

>taskkill /PID /F

java error invalid source release 15 in intellij Idea Solved error

While the spring boot project was running project in IntelliJ idea I got the following error:

language level is invalid or missing in pom.xml. current project jdk is 15

and this also;

java error invalid source release 15

This issue will occur when you have two or more java versions installed in machine.

I did the following to solve the issue:

Go to File->Project Setting and check “Project SDK” and “Project Language Level”

Then go to Modules and select the same version as the JAVA version.

This setting will solve your issue.

blocked cors localhost:3000 springboot issue

I tried to fetch localhost:8080 spring-boot application and I got the following error in the console.

Access to XMLHttpRequest at 'http://localhost:8080/' from origin 'http://localhost:3000' has been blocked by CORS policy:

I did the following changes in SpringSecurityConfig class file:

    
@Override
protected void configure(HttpSecurity http) throws Exception {    
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling()
    .authenticationEntryPoint(restAuthEntry).and()
    .authorizeRequests((request) -> request.antMatchers("/api/v1/auth/login").permitAll()
            .antMatchers(HttpMethod.OPTIONS, "/**").permitAll())
    .addFilterBefore(new JWTAuthenticationFilter(userService, jWTTokenHelper),
            UsernamePasswordAuthenticationFilter.class);
    http.csrf().disable().cors().and().headers().frameOptions().disable();
}

This solved..

wsl issue code visual studio not working windows 10 ubuntu console

I installed docker desktop and ubuntu on windows 10. I followed the following tutorial:
https://code.visualstudio.com/docs/remote/wsl-tutorial

When I was trying to run on the ubuntu console. I got the following error:

/usr/share/code/bin/../code: error while loading shared libraries: libXss.so.1: cannot open shared object file: No such file or directory

I did not install VS code through the installer due of this error was coming.
Fix for this is.

Run this command on the Ubuntu console:

alias code="/mnt/c/NON-INSTALLED-SOFTWARES/VSCode-win32-x64-1.61.0/Code.exe"

This fixed my issue.

Without changing, ownership of folder give read-write permission Linux

If you want to give read and write permission to a folder in Linux os (fedora, centos, ubuntu then use the following command:

#setfacl -R -m u:YOUR_USERNAME:rwx FOLDER_NAME

This command will be helpful for other Linux users to change files and folders.

Cakephp Invalid key for decrypt(), key must be at least 256 bits (32 bytes) long: Solved

In cakephp 3 I tried to set cookie in my controller using write cookie method. Error got invalid key for decrypt(), key must be at least 256 bits (32 bytes) long – used following line of code.

$this->Cookie->write(‘username’, ‘test’, true, ‘1 year’);

I got following error after execting page.
Invalid key for decrypt(), key must be at least 256 bits (32 bytes) long

Before using cookie write method, I loaded cookie component in appcontroller using following line.
$this->loadComponent(‘Cookie’);

I loaded conponnet in initialize method (appcontroller.php)

After searching I found following solution. I changed app.php file and added following line of code

'Security' => [
        'salt' => '123456789purab@eparinay!@#*$($(',
    ]

Above solution worked for me and it solved issue.

If you are getting this error means your Security.salt in app.php does not have the correct length.

cakephp 3 getOriginalSubject undefined index issue fixed

I am using cakephp 3.1 for development one of my portal. While configuring email Igot undefined index getOriginalSubject in DebugkitTransport.php. I searched for some time on net for solution but I did not find any solution. This function tries to get subject from email obejct. I think this is bug in cakephp 3.1.

My solution is as follows. I opened DebugkitTransport.php file and in send function I changed following line


/fixing issue of $email->getOriginalSubject undefined index
$headers['Subject'] = $email->subject();

Above line fixed my issue and I am able to send email now. I using smtp setting for sending email. I am using following code for one of my site called http://eparinay.com


$email = new Email();
$email->transport('eparinay');
try {
$email->template('eparinay')
->emailFormat('html')
->to($email)
->bcc('purabdk@yahoo.co.in')
->from(['noreply@eparinay.com' => 'eParinay.com'])
->viewVars(array('username' => $username, 'email' => $email))
->subject('eParinay.com: New registration.')
->send();
} catch (Exception $e) {

echo 'Exception : ', $e->getMessage(), "\n";
}

 

Get base url or development URL in cakephp 3 and use in view ctp file

Getting baseurl in any framework is easy. But development URL in cakephp 3 in view file…took time…For adding css or js or other purpose we need base path cakephp.

While doing development my path was http://localhost/cakephp3/. I wanted to fetch that in my site.
Their are many ways we can get the path.

You can use any one method of following :

<?php 
    echo $this->Html->url('/', true)
    echo $this->Html->url('/');
    ?>

Define constant in Config/core.php as given bellow:

define(“BASE_URL”, “localhost/cakephp3/”);

Then you can use BASE_URL in view file.

For view file you can use following code.

<?php echo $this->Url->build('/', true); ?>

I used above code reference to following URL:
http://book.cakephp.org/3.0/en/views/helpers/url.html#generating-urls

 

Avoid subquery get records with max value for each group of grouped mySQL results

How do you get the rows that contain the max value for each grouped set. I faced issue many times but I ended with following solution of subquery and two queries and using one resultset result in another query.

Here is data of Employee table. I want max salary role based..users
Employee table Data:

Name	Salary	Role
David	130,000	Software Engineer
John	140,000	DevOps Engineer
Bob	120,000	Software Engineer
Sarah	130,000	DevOps Engineer
Alice	110,000	Software Engineer
Steve	95,000	DevOps Engineer

Old query which takes too much time and memory.

SELECT *
FROM Employee a
JOIN
(
SELECT max(salary) FROM Employee c
GROUP BY c.role
) b
ON a.ID = b.ID
ORDER BY book_count DESC LIMIT 1

Finally I found this query which solved my problem. following is correct query. I used this type query with 8CR rows..It works perfectly fine..But you need understand this.. Try to explain query before using it and do proper indexing…on column which are used in left outer join….

SELECT emp1.*, emp2.ID FROM
Employee AS emp1
LEFT OUTER JOIN Employee AS emp2 ON emp2.role = emp1.role AND emp2.salary > emp1.salary
WHERE emp2.salary IS NULL;

query result:

David	130,000	Software Engineer	NULL
John	140,000	DevOps Engineer	        NULL

Please note – for this solution to work, you need to make sure you have the correct index in place. In this example, you’ll need to create an index that includes the role and salary columns in order to avoid full table scans.

 

I found following articles Useful:

https://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/