Embedding ICO Icons in Tkinter

Embedding ICO Icons in Tkinter Although Tkinter is fairly basic, it is still quite convenient when developing some graphical gadgets with Python. Since the native icon is rather plain, a custom icon is generally chosen instead, but then a single-file executable program also has to be shipped with an ICO file to display the icon, which is undoubtedly cumbersome. This article describes how to embed the icon into the executable file. ...

2023-10-30 · 1 min · 3rd

C++ Singleton Template

C++ Singleton Template Singleton implementations are mostly the same. A template makes the singleton pattern more convenient to use. Analysis The singleton pattern must ensure that resource initialization is thread-safe, which has led to the following approaches (selected from “Template Implementation of C++ Singleton Pattern” and “Is the Singleton Pattern Simple? But Can You Really Get It Right?”): ...

2023-06-29 · 6 mins · 3rd

What Is Reflection in Programming?

What Is reflection reflection ’s human ’s , has ’s . Digestcalculate, among them, has as follows:code: 1 2 3 4 5 6 if selected_algorithm == "SHA-512": algorithm = hashlib.sha512() elif selected_algorithm == "SHA-256": algorithm = hashlib.sha256() else: algorithm = hashlib.md5() code is userchoose ’s Digestcalculateway,Creating ’s object,very ’s method. but is has ,cannotmore?reflection: 1 2 3 4 if hasattr(hashlib, selected_algorithm): algorithm = getattr(hashlib, selected_algorithm)() else: algorithm = hashlib.md5() a kind of Digestalgorithm,program,;Usingreflection, can runtime,choose ’s string ’s methodcall. ,cost is ?cost is someefficiency. Java has Usingreflection, for example, ’s Spring. ...

2023-04-11 · 1 min · 3rd

Setting Up a Private Git Service with Gitea

Setting Up a Private Git Service with Gitea There is always code that doesn’t fit on someone else’s server, so why not build your own Git service. This tutorial uses Docker, making deployment easy, migration simple, and it supports https. Steps 1. Preparation Pick a path you like and create a new folder to store all the files that come later. Here I recommend naming it Gitea. Then create ./docker-compose.yml for quickly deploying the container. ...

2023-02-19 · 3 mins · 3rd

Using External Tools in PyCharm

Using External Tools in PyCharm This thing is really handy, especially for packaging with pyinstaller — one-click packaging, no need to keep typing commands. Steps 1. Getting Started Open Settings, find the External Tools option as shown in the figure, and open it. Getting Started 2. Create a New External Tool An external tool is a set of predefined commands. When you use it, macros are replaced based on the file to produce the final command, which is then executed automatically. In short, it saves you the time spent typing commands — a few mouse clicks and the pyinstaller command is invoked to package your script. Let’s take that as an example below. ...

2022-10-07 · 2 mins · 3rd

SHA Message Digest

SHA Message Digest The Secure Hash Algorithm (SHA) is a family of cryptographic hash functions certified by FIPS. It computes a fixed-length string (also known as a message digest) from a given digital message, with a very high probability that different messages will produce different strings. 1. Introduction to SHA SHA currently has four algorithm versions: SHA-0, SHA-1, SHA-2, and SHA-3. The most widely used today is SHA-2. SHA function comparison Algorithm and variant Output hash value length (bits) Intermediate hash value length (bits) Block size (bits) Maximum input message length (bits) Number of rounds Operations used Collision attack (bits) Performance example[3] (MiB/s) MD5(for reference) 128 128 (4 × 32) 512 Unlimited[4] 64 And, Xor, Rot, Add (mod 232), Or ≤18 (collision found) 335 SHA-0 160 160 (5 × 32) 512 264 − 1 80 And, Xor, Rot, Add (mod 232), Or <34 (collision found) - SHA-1 160 160 (5 × 32) 512 264 − 1 80 <63[5] (collision found[6]) 192 SHA-2 SHA-224 SHA-256 224 256 256 (8 × 32) 512 264 − 1 64 And, Xor, Rot, Add (mod 232), Or, Shr 112 128 139 SHA-384 SHA-512 SHA-512/224 SHA-512/256 384 512 224 256 512 (8 × 64) 1024 2128 − 1 80 And, Xor, Rot, Add (mod 264), Or, Shr 192 256 112 128 154 SHA-3 SHA3-224 SHA3-256 SHA3-384 SHA3-512 224 256 384 512 1600 (5 × 5 × 64) 1152 1088 832 576 Unlimited[7] 24[8] And, Xor, Rot, Not 112 128 192 256 - SHAKE128 SHAKE256 d (arbitrary) d (arbitrary) 1344 1088 min(d/2, 128) min(d/2, 256) - Since the various SHA-2 algorithm variants differ only slightly in digest length, number of rounds, and other minor details while sharing the same basic structure, and since there are many detailed explanations of SHA-256 available online, we will use SHA-256 as our working example here. ...

2022-09-12 · 6 mins · 3rd

Header-File Design and Usage Guidelines

Header-File Design and Usage Guidelines As is well known, compared with object-oriented C++, procedural C has no concept of encapsulation, inheritance, or polymorphism, let alone interfaces. In C programs, using the principle of separate compilation, header files (.h or .hpp) serve to provide declarations and interfaces, while source files (.c) provide implementations, thereby achieving modular engineering design and ensuring high cohesion and low coupling. This is undoubtedly very important. Preface Preface 1. Disclaimer The content of this article is largely derived from “C — Principles, Rules, and Recommendations for Header-File Inclusion”, but that article has poor formatting, so the content has been reformatted and excerpted here. ...

2022-08-09 · 4 mins · 3rd

Modulo and Remainder

Modulo and Remainder A brief analysis of these two operations. For integers $a$ and $b$, the modulo or remainder operation proceeds in two steps: Compute the integer quotient: c=a/b Compute the modulus or remainder: r=a-(c*b) The difference lies in the first step. The remainder operation truncates the quotient toward zero — so $3.3$ and $-3.3$ become $3$ and $-3$. The modulo operation truncates the quotient toward negative infinity — so $3.3$ and $-3.3$ become $3$ and $-4$. For example, 4/(-3) ≈ -1.33: ...

2022-08-04 · 1 min · 3rd

C++ Polymorphism

C++ Polymorphism Polymorphism, as the name suggests — many forms. In plain terms, it means “one interface, multiple implementations.” (At the time of writing, my knowledge framework was not yet fully developed; please feel free to point out any omissions or errors.) 1. Why Do We Need Polymorphism? In engineering, we frequently encounter ever-changing requirements. If we design a separate interface and logic for every requirement, it would inevitably lead to a large amount of code redundancy and reduced maintainability. ...

2022-07-09 · 10 mins · 3rd