Featured image of post Weekly Report 2024.12

Weekly Report 2024.12

long lasting recovery

The priorities you think you have VS. The priorities your actions show you have.

Entertainment

Demon Destruction

What should I categorize this manga, Denpa SF?

After the storyline mentioned multi-universe, the ending really didn’t matter at all. If you were asking, I would say the world-0 is a little bit more realistic.

Learning

Find Duplicates in 1~n array

If we can modify the original array, we can iterate the array, make every number[idx] to negative. And the next we meet a negative number, that’s the one duplicated.

1
2
3
4
5
6
7
8
class Solution:
   def solution(self, nums) -> int:
      for n in nums:
         idx = abs(n)
         if nums[idx] < 0:
            return idx
         nums[idx] = -nums[idx]
      return -1

If it’s not allowed to in-place modification, use slow-fast pointer strategy.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class Solution:
   def solution(self, nums) -> int:
      slow, fast = nums[0], nums[nums[0]]
      while slow != fast:
         slow = nums[slow]
         fast = nums[nums[fast]]
      # reset to start point
      fast = nums[0]
      while slow != fast:
         slow = nums[slow]
         fast = nums[fast]
      return slow

Life

  • a rainy week
  • Yokohama is a better place to live comparing to Tokyo, I think
  • And I really don’t have a strong feeling towards Sakura
  • Also, I think Shrimp is my favorite now
  • Finally, I still have to contribute more time and energy to personal growth, to get out of this frustrating life condition.

Sharing

  • It’s easier to get a smart person to do something hard than to get them to do something easy that doesn’t matter.

Docker Tricks

  1. multi-stage build
    1. optimize build cache utilization
    2. minimize final image size
    3. label build stages
  2. squashing image layers
    1. otpmizing image size
    2. simplifying image layers
  3. docker buildkit secrets
    1. minimize secret exposure
    2. scoped secrets
    3. version pinning
  4. leverage .dockerignore
  5. health checks in Dockerfiles
  6. docker cli output formatting
    1. docker ps --format '{{.ID}}'
    2. docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
  7. optimizing cache use in builds
  8. docker events for monitoring
    1. docker events --filter 'type=container'
    2. docker events --filter 'type=container' --filter 'event=start' --filter 'event=stop' --filter 'label=environment=prod'
  9. running containers in read-only mode
    1. docker run --read-only --tmpfs /tmp -d myimage:latest
    2. security-sensitive/stateless applications, to enforce immutability
  10. cleaning up with docker prune
    1. docker image/volume/network prune
    2. docker system prune -a --volumes
  11. overriding entrypoint for debugging
    1. docker run --entrypoint /bin/sh -it myimage:latest
  12. docker contexts for multi-environment management
1
2
3
4
5
# enable docker buildkit
export DOCKER_BUILDKIT=1

# command
docker build --secret id=mysecret,src=/path/to/secret/file.txt -t myapp:latest .
1
2
FROM alpine
RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret

References

Licensed under CC BY-NC-SA 4.0
Last updated on Jan 09, 2024 11:32 CST
The older I get, the more I realize that most of life is a matter of what we pay attention to, of what we attend to [with focus].
Built with Hugo
Theme Stack designed by Jimmy