Posts

Plain Javascript to get current datetime with Timezone

That's why I hate javascript, it is too complicated. const now = new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, '0'); const day = String(now.getDate()).padStart(2, '0'); const hours = String(now.getHours()).padStart(2, '0'); const minutes = String(now.getMinutes()).padStart(2, '0'); const seconds = String(now.getSeconds()).padStart(2, '0'); const dateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; console.log(dateTime); 

Why can't I build AWS OpenSearch/ElasticSearch index, which I could do that before?

One of the reason when you used to build AWS OS/ES index, and you can't do that now, is that there is a maximum shard default setting in AWS, which is 1000 shards. If you continuously build index, yet you did not remove old indices, there will be an increasing number of shards that occupied OS/ES. Until when a new index is built, and new shard is created that exceed the number of maximum shard, you got an error. Solution: Remove old/existing OS/ES indices. While it works for AWS, if you are using on-premise, it should be applied as well. Hope it helps someone.

[Easy to understand] What are Service, Service Container and Service Provider in PHP Laravel?

Imagine you are running a restaurant. Let's break down the concepts of Service, Service Container, and Service Provider using this restaurant analogy: Service: In our restaurant analogy, a service is like a specific task or job that needs to be done. For example, a "Waiter Service" would involve taking orders, serving food, and delivering the bill to the customers. Each service has a specific responsibility. Service Container: The service container is like the restaurant itself. It holds all the services (tasks) that need to be performed. Just like how a restaurant has different sections (kitchen, dining area, bar), the service container in Laravel holds different services that can be accessed when needed. When a customer (controller) needs a specific service (task), they ask the restaurant (service container) to provide it. Service Provider: The service provider is like the manager of the restaurant. They are responsible for setting up the restaurant, organizing the serv

[Easy to understand] What is Kafka Consumer, Consumer Group, Topic & Partition?

Kafka: Kafka is a distributed streaming platform that allows you to publish and subscribe to streams of records, similar to a message queue or enterprise messaging system. Consume: Consuming in Kafka means reading data from a topic. Consumers read messages from topics and process them. Consumer Group: A consumer group is a set of consumers that cooperate to consume data from Kafka brokers. Each message within a topic is delivered to one consumer instance within each subscribing consumer group. This allows you to scale processing by adding more consumers to a group. Topic: A topic is a category/feed name to which records are sent by producers. Topics in Kafka are always multi-subscriber; that is, a topic can have zero, one, or many consumers that subscribe to the data written to it. Partition: Topics in Kafka are divided into partitions. Each partition is an ordered, immutable sequence of records that are continually appended to. Each message within a partition is assigned a unique offs

[Easy to understand] Apache Kafka Listener and Advertised Listener

A plain, simple, even novice can understand explanation on what is Apache Kafka LISTENER and ADVERTISED_LISTENER. Imagine you are hosting a big party where people need to communicate with each other. In the world of Apache Kafka, the "Listener" is like the door or entrance to your party. It's where your guests (data producers and consumers) come in to interact with Kafka. Now, let's talk about the "Advertised Listener." This is like the address you give to your guests so they know how to find your party. Just like you might share your home address with friends to visit you, in Kafka, the Advertised Listener is the address that other services or clients use to connect to Kafka. In simpler terms, the Listener is where the communication happens within the Kafka system, while the Advertised Listener is the address that is shared with external services to connect to Kafka. For example, let's say your Kafka server has an internal IP address of 192.168.1.100 b

How to use aws-lambda-python docker image with example in VSCode for local development

Image
Docker image: https://hub.docker.com/r/amazon/aws-lambda-python This docker image lacks working example on how to use. If you just want to test your lambda with this image locally, please read on. Let's assume the following: Your script is called `my_python.py` The function in this file that you want to execute is called `lambda_handler` Here is the docker command (I'm using windows): docker run --rm \ -p 9000:8080 \ --mount type=bind,src=/c/projects/my_lovely_proj,target=/var/task \ amazon/aws-lambda-python \ my_python.lambda_handler Brief explanation on above: --rm : Remove the container after terminating the script (i.e. Ctrl + C in command line).  So you don't need to run `docker stop <container_id>` and `docker rm <container_id>` -p 9000:8080: map the port of local machine 9000 to container port 8080.  This is super important and will be explained later. --mount: Mount the dir to /var/task in container.  All lambda script will be executed in this /var/task

Add WordPress Admin User via Database 2024 (and onwards)

If you are trying to add a user (probably admin), not using UI but via database directly.  Here is what you did. Refer to the following article to add a user to DB https://hk.godaddy.com/en/help/create-an-admin-user-in-the-wordpress-database-27023 (Recommended) https://help.one.com/hc/en-us/articles/17467509114385-How-to-add-an-Admin-User-to-the-WordPress-database https://wpengine.com/support/add-admin-user-phpmyadmin/ They are all talking about same steps, so just pick one and follow.  In case if you don't understand first article, read the next one and so on. Remember, if you are updating existing DB to use new prefix, you need to manually (or via SQL) update all table name to use your prefix. For example, if original prefix is 'wp_', and you want to change it to "my_lovely_", you need to update all table names, like "wp_posts" > "my_lovely_posts". Here is the missing steps:  Thanks to my colleagues, you also need to update {prefix}_optio

Nginx HTTP2 directive old vs new test result

 The nginx "http2" directive appended after "listen" is deprecated since 1.25.1. Let's see if Nginx will start under old and new version if we put this directive incorrectly Nginx after v1.25.1 server {     listen 80 http2;  # Work, but will issue deprecated warning during start     http2 on; ... } Nginx before v1.25.1 server {     listen 80 http2;       http2 on; # Not work, issue error: unknown directive http2 ... } Conclusion: - Appending http2 in Nginx latest version is OK, even if the the correct directive is `http2 on;` - Do not use standalone `http2 on;` on unsupported Nginx version, it will fail to start. Hope it helps someone.