Friday, March 31, 2023

Monday, March 27, 2023

ChatGPT in ESLint (I will soon lose my job, replaced by this little bastard...)

Question: 

 

please write a ESLint rule to flag as deprecated the usage of variable names like Button.size.NORMAL

Answer:


To write an ESLint rule to flag the usage of variable names like Button.size.NORMAL, you can use the following code:

vbnet

module.exports = {
  rules: {
    "no-deprecated-variable-name": {
      meta: {
        deprecated: true,
        type: "problem"
      },
      create: function(context) {
        return {
          MemberExpression(node) {
            const { object, property } = node;
            if (object.type === "Identifier" && object.name === "Button" &&
                property.type === "MemberExpression" && property.property.name === "NORMAL") {
              context.report({
                node: property.property,
                message: "The use of 'Button.size.NORMAL' is deprecated. Use a different value instead."
              });
            }
          }
        };
      }
    }
  }
};

This rule creates a new ESLint rule called no-deprecated-variable-name, which checks for the usage of Button.size.NORMAL variables. When the rule encounters this variable, it reports a warning message to the user indicating that the usage of this variable is deprecated and suggests using a different value instead.

To use this rule, you will need to add it to your .eslintrc configuration file:

json

{
  "rules": {
    "no-deprecated-variable-name": "warn"
  }
}

In this configuration, the rule is set to "warn", which means it will produce a warning message but will not fail the build. You can set it to "error" to make it fail the build.




Sunday, March 19, 2023

Reverse Proxy with Docker httpd container on Windows

 https://www.middlewareinventory.com/blog/docker-reverse-proxy-example/

 

I have followed these instructions for Windows and it works, the only change I had to do is to start the container with the  "--net=host" options, and from the container I had to configure the ReverseProxyPass to use the IP address of the host (NOT the WSL IP).



Reverse Proxy with Spring Boot

https://github.com/vernetto/myreverseproxy/blob/master/src/main/java/org/pierre/myreverseproxy/CharonConfiguration.java 

 

I really like the simplicity and power of this CHARON, a Spring Boot- based Swiss knife for load balancing and request forwarding. 

 

Here a lot more examples https://github.com/mkopylec/charon-spring-boot-starter/blob/master/charon-spring-webmvc/src/test/java/com/github/mkopylec/charon/test/ReverseProxyConfiguration.java  



Saturday, March 18, 2023

Reverse Proxy with nodejs

https://github.com/http-party/node-http-proxy
npm install http-proxy --save
node .\server.js

var http = require('http'),
    httpProxy = require('http-proxy');
//
// Create your proxy server and set the target in the options.
//
httpProxy.createProxyServer({target:'http://localhost:10090'}).listen(8000);




Docker container connecting to host service on Windows

docker run -d -p 80:80 --name webserver nginx
docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                NAMES
2733688156aa   nginx     "/docker-entrypoint.…"   14 seconds ago   Up 13 seconds   0.0.0.0:80->80/tcp   webserver


on my windows host I have a Spring Boot application running at port 10090:
netstat -an | grep 10090
  TCP    0.0.0.0:10090          0.0.0.0:0              LISTENING
  TCP    [::]:10090             [::]:0                 LISTENING
  TCP    [::1]:53110            [::1]:10090            TIME_WAIT
  TCP    [::1]:53123            [::1]:10090            TIME_WAIT
  TCP    [::1]:53126            [::1]:10090            TIME_WAIT

and I can also see the nginx container
netstat -an | grep 80
  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING
  TCP    [::]:80                [::]:0                 LISTENING
  TCP    [::1]:80               [::]:0                 LISTENING


If in browser you type "localhost" you should get nginx welcome page (at port 80, default)

Now log into container:
docker exec -it webserver sh

from the container you can connect to
curl host.docker.internal
curl host.docker.internal:10090
they both work, because they "resolve to the internal IP address used by the host"
On my Windows host, if I type "ipconfig" I see that I have
Ethernet adapter vEthernet (WSL): 172.28.176.1
Ethernet adapter Ethernet: 192.168.0.248
If I try:
curl 172.28.176.1:10090
curl 192.168.0.248:10090
they both work on both host and container, but the first is a lot more responsive.
This proves that from container you can access a service running on host.

References:

http://man.hubwiz.com/docset/Docker.docset/Contents/Resources/Documents/docs.docker.com/docker-for-windows/networking.html

NB: besides host.docker.internal , also docker.for.win.localhost can be used, but they have different values (which?)

Saturday, March 11, 2023

Intellij Java remote debug with SSH tunnel

This is the simplest explanation how to do it:
https://arjon.es/2014/remote-debug-of-a-java-app-using-ssh-tunneling-without-opening-server-ports/ (it is a bit confusing, as is uses localhost for both remote and local)
and
https://www.revsys.com/writings/quicktips/ssh-tunnel.html which clearly runs the ssh command locally forwarding to remote and highlights the role of -N parameter)
also worth reading:
https://www.jetbrains.com/help/idea/remote-debugging-via-ssh-tunnel.html#troubleshooting this is about PHP debugging

SSH tunneling explained visually https://www.youtube.com/watch?v=N8f5zv9UUMI

this command does the trick:
ssh -f user@personal-server.com -L 9999:personal-server.com:9999 -N

Chrome Developer Tools devtools

2 interesting crash courses : https://www.youtube.com/watch?v=gTVpBbFWry8
https://www.youtube.com/watch?v=gTVpBbFWry8