Sunday, March 19, 2023

Use flask for auspix

 pip3 install flask

set FLASK_APP=auspix_service.py

flask run --host=0.0.0.0


I put the below content into a bat file auspix_serbice.bat

set FLASK_APP=auspix_service.py && flask run --host=0.0.0.0 >> C:/Auspix/logs/auspix_service_log.txt

And tried to add it into task scheduler (at system startup or daily...) but all cannot work as expected.

Then I added it into the startup folder according to this article

https://www.minitool.com/data-recovery/windows-11-startup-programs-folder.html

1. Press Windows + R, type shell:startup, and press Enter to open Windows 11 startup folder.

2. Create a shortcut for the bat file, and move the shortcut file into the startup folder. Now it works like a charm





Saturday, March 18, 2023

bible quotes from the shawshank redemption

 

Watch ye therefore: for ye know not when the master of the house cometh. Mark 13:35

I am the light of the world. Whoever follows me will not walk in darkness, but will have the light of life.

John 8:12

Thursday, March 16, 2023

I asked chatGPT to create the Java implementation using spring boot to connect to object grid

Give me the implementation using Spring boot to connect to object grid.

Sure, here is an example implementation using Spring Boot to connect to IBM Object Grid:

  1. First, add the following dependencies to your Spring Boot project's pom.xml file:
<dependency>
    <groupId>com.ibm.websphere.objectgrid</groupId>
    <artifactId>objectgrid-client</artifactId>
    <version>8.6.1.0</version>
</dependency>
<dependency>
    <groupId>com.ibm.websphere.objectgrid</groupId>
    <artifactId>objectgrid-common</artifactId>
    <version>8.6.1.0</version>
</dependency>

  1. Create a configuration class to set up the ObjectGrid connection:
@Configuration public class ObjectGridConfig { @Value("${og.client.config.file}") private String clientConfigFile; @Bean public ObjectGrid getObjectGrid() throws FileNotFoundException, ObjectGridException { ClientClusterContext ccc = ObjectGridManagerFactory.getObjectGridManager() .getClientClusterContext(new FileInputStream(clientConfigFile)); return ObjectGridManagerFactory.getObjectGridManager().getObjectGrid(ccc, "myGrid"); } }

  1. Use the ObjectGrid in your application:
@Service public class MyService { private ObjectGrid objectGrid; @Autowired public MyService(ObjectGrid objectGrid) { this.objectGrid = objectGrid; } public void addObjectToGrid(String key, Object value) { Grid grid = objectGrid.getGrid(); GridMap<String, Object> map = grid.getMap("myMap"); map.put(key, value); } public Object getObjectFromGrid(String key) { Grid grid = objectGrid.getGrid(); GridMap<String, Object> map = grid.getMap("myMap"); return map.get(key); } }

4. The clientConfigFile in the ObjectGridConfig class is a path to a configuration file that specifies the ObjectGrid connection details for the client.

Here is an example of what the contents of clientConfigFile might look like

<?xml version="1.0" encoding="UTF-8"?> <ogclient:ogclient xmlns:ogclient="http://www.ibm.com/websphere/appserver/schemas/8.5/objectgrid/client"> <ogclient:server> <ogclient:serverdef name="myGridServer" host="localhost" port="2809" /> </ogclient:server> <ogclient:catalog> <ogclient:catalogentry name="myGrid" gridName="myGrid" /> </ogclient:catalog> </ogclient:ogclient>

5.
  1. Add the following dependencies to your project's pom.xml file, if they are not already included:
  2. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency>
@RestController @RequestMapping("/my-grid") public class MyGridController { private ObjectGrid objectGrid; @Autowired public MyGridController(ObjectGrid objectGrid) { this.objectGrid = objectGrid; } @GetMapping("/{key}") public ResponseEntity<Object> getObject(@PathVariable String key) { Grid grid = objectGrid.getGrid(); GridMap<String, Object> map = grid.getMap("myMap"); Object value = map.get(key); if (value != null) { return ResponseEntity.ok(value); } else { return ResponseEntity.notFound().build(); } } @DeleteMapping("/{key}") public ResponseEntity<Void> deleteObject(@PathVariable String key) { Grid grid = objectGrid.getGrid(); GridMap<String, Object> map = grid.getMap("myMap"); Object value = map.remove(key); if (value != null) { return ResponseEntity.noContent().build(); } else { return ResponseEntity.notFound().build(); } } }
  1. Run the Spring Boot application and make RESTful requests to the endpoints. For example, you can use the following curl commands to test the endpoints:
# Retrieve an object by key
curl -X GET http://localhost:8080/my-grid/my-key

# Delete an object by key
curl -X DELETE http://localhost:8080/my-grid/my-key

sh

Sunday, March 12, 2023

Oauth2 Gmail refresh token expire problem

 Google said it's refresh token never expires:

"Note: The OAuth Playground does not store refresh tokens, but as refresh tokens never expire, user should go to their Google Account Authorized Access page if they would like to manually revoke them."

https://developers.google.com/oauthplayground/


However, for the personal project if the publish status is "Testing", it would expire in 7 days:


The following can be read from the Google document Using OAuth 2.0 to Access Google APIs, the section Refresh token expiration:

A Google Cloud Platform project with an OAuth consent screen configured for an external user type and a publishing status of "Testing" is issued a refresh token expiring in 7 days.


https://stackoverflow.com/questions/8953983/do-google-refresh-tokens-expire 

The solution is to publish (ignore the requirement, no verification), so the publishing status is "In production", then it won't expire any more.


 

Saturday, March 11, 2023

Mac Ventura scheduled shutdown and poweron

 peterpeng@Peters-Mac-mini ~ % sudo pmset repeat wakeorpoweron MTWRFSU 20:00:00 shutdown MTWRFSU 5:00:00

peterpeng@Peters-Mac-mini ~ % sudo pmset -g sched                                                      

Repeating power events:

  wakepoweron at 8:00PM every day

  shutdown at 5:00AM every day





Wednesday, March 1, 2023

Spring boot controller vs restcontroller

RestController = Controller + @ResponseBody

If use controller annotation only, the controller will try to resolve view, if it can't find/resolve the view, 500 error will raise.

when we use @ResponseBody, we are saying that we do not want a view produced. We just want to send the return object as the body, in whatever format we specify. We wouldn't want it to be a serialized Java object (though possible). So yes, it needs to be converted to some other common type. The choice of the format depends on the installed message converters, on the values of the produces attribute of the @RequestMapping annotation, and on the content type that the client accepts (that is available in the HTTP request headers). For example, if the request says it accepts XML, but not JSON, and there is a message converter installed that can transform the list to XML, then XML will be returned.

https://stackoverflow.com/questions/28646332/how-does-the-spring-responsebody-annotation-work

One end you have the MVC architecture, which is based on your normal web app, using web pages, and the browser makes a request for a page:

Browser <---> Controller <---> Model
               |      |
               +-View-+

The browser makes a request, the controller (@Controller) gets the model (@Entity), and creates the view (JSP) from the model and the view is returned back to the client. This is the basic web app architecture.

On the other end, you have a RESTful architecture. In this case, there is no View. The Controller only sends back the model (or resource representation, in more RESTful terms). The client can be a JavaScript application, a Java server application, any application in which we expose our REST API to. With this architecture, the client decides what to do with this model. Take for instance Twitter. Twitter as the Web (REST) API, that allows our applications to use its API to get such things as status updates, so that we can use it to put that data in our application. That data will come in some format like JSON.


Dr. Peter Attia: Exercise, Nutrition, Hormones for Vitality & Longevity - Note

 

-From birth to say 20 you're in growth, from 20 to 50 you plateau. At 50 men start to decline but it's really small. Women start to decline, and it's precipitious.

-And it's related to the drop in estrogen assocaited with menopause or premenopause?

-Correct.

estrogen

menopause