| Language / Platform | Function / Method & Usage |
|---|---|
| Java ☕ | MessageDigest.isEqual(byte[], byte[])This static method securely compares two byte arrays in constant time. Always convert strings to byte arrays with a consistent encoding (e.g., UTF-8) before comparison. |
| JavaScript (Node.js) 📜 | crypto.timingSafeEqual(Buffer, Buffer)Node.js provides this dedicated function in its crypto module. True constant-time comparison is difficult in browsers, so sensitive comparisons should be handled server-side. |
| Python 🐍 | hmac.compare_digest(bytes, bytes)This function securely compares two byte strings in a constant-time manner to prevent timing attacks. Ensure your inputs are byte strings. |
| Go 🐹 | crypto/subtle.ConstantTimeCompare(a, b []byte)Go's standard library provides this function for constant-time byte slice comparison. It returns 1 if the slices are equal and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ConcurrentModificationException; | |
| import java.util.concurrent.ExecutorService; | |
| import java.util.concurrent.Executors; | |
| import java.util.concurrent.TimeUnit; | |
| /** | |
| * Asynchronous Queue | |
| *<p> | |
| * Article at: https://www.digitalturbine.com/blog/java-class-for-easy-multithreaded-loops/ | |
| *<p> |
There are 3 plugins for generating to create a JAR-File in maven:
- maven-jar-plugin
- maven-assembly-plugin
- maven-shade-plugin
maven-jar-plugin:This plugin provides the capability to build and sign jars.But it just compiles the java files under src/main/java and /src/main/resources/.It doesn't include the dependencies JAR files.
<!--exclude all xml files from the jar-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import static org.hamcrest.MatcherAssert.assertThat; | |
| import static org.hamcrest.Matchers.equalTo; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import java.io.OutputStream; | |
| import java.nio.charset.StandardCharsets; | |
| import java.util.Arrays; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.List; | |
| /* | |
| * Test program to show how to remove warnings from generic array construction. | |
| * First step: Remove any raw types, by adding <?> as needed. | |
| * Second step: Add a cast if needed, to the specific non-wildcard type. | |
| * Third step: Suppress "unchecked" warnings on the cast. | |
| * The point of the first step is to remove the "rawtypes" warning | |
| * cleanly, without resorting to an additional warning suppression. | |
| * Note that every use of @SuppressWarnings should have a comment. |