Skip to content

Instantly share code, notes, and snippets.

@tivrfoa
tivrfoa / process-file-in-parallel-in-Java-by-ChatGPT.md
Created March 2, 2025 13:51
Java: processing different chunks of a file in parallel

Prompt: So to process different chunks of a file in parallel, is RandomAccessFile the only option is to use ?


ChatGPT:

No, RandomAccessFile is not the only option. There are several alternatives for processing different chunks of a file in parallel:

  1. FileChannel and MappedByteBuffer:
  • Using a FileChannel, you can memory-map a file (or portions of it) into a MappedByteBuffer with the map() method.
@tivrfoa
tivrfoa / useful-shell-commands.sh
Created February 28, 2025 22:24
Useful shell commands
# find files that contain the string STR and delete them
find src/main/java -type f -exec grep -q "STR" {} \; -delete
@tivrfoa
tivrfoa / Java-TreeSet-vs-PriorityQueue-Benchmark.md
Last active February 28, 2025 19:42
Java benchmark program using JMH (Java Microbenchmark Harness) to compare the performance of TreeSet and PriorityQueue.

Prompt: Write a Java benchmark program using JMH, that benchmarks TreeSet vs PriorityQueue.


Here is a complete Java benchmark program using JMH (Java Microbenchmark Harness) to compare the performance of TreeSet and PriorityQueue. The benchmark focuses on three key operations: adding elements, adding and removing the smallest element, and checking for element existence. Benchmark Overview We will measure the performance of TreeSet and PriorityQueue for the following operations:

Adding Elements:

@tivrfoa
tivrfoa / ripgrep-code-components.md
Created February 28, 2025 17:18
ripgrep analysis
@tivrfoa
tivrfoa / C_and_C-Tiberian-Dawn-BULLET.CPP.md
Created February 28, 2025 16:47
C&C Tiberian Dawn Bullet.CPP Analysis by Google AI Studio Gemini 2.0 Pro Experimental 02-05

Let's break down the BULLET.CPP code from the Command & Conquer: Tiberian Dawn Remastered Collection source. This file defines the behavior of bullets (and similar projectiles) within the game.

Core Concepts and Purpose

This file is responsible for:

  1. Bullet Creation: Defining how bullets are spawned (created) in the game world.
  2. Bullet Movement: Handling the trajectory and movement of bullets across the map.
  3. Bullet Impact: Determining what happens when a bullet hits something (a unit, building, or terrain).
  4. Bullet Lifetime: Managing how long a bullet exists before disappearing.
@tivrfoa
tivrfoa / java-interview-question-recursion.md
Created February 23, 2025 13:42
Prompting ChatGPT: write a Java interview question where recursion is a good solution

Java Interview Question: Using Recursion to Solve a Problem

Question:

You are given a nested list of integers, where each element is either an integer or another list of integers. Implement a function in Java that sums all integers in the nested list, regardless of how deeply nested they are.

Example Input:

List<Object> nestedList = List.of(1, List.of(2, 3, List.of(4, 5)), 6);

Expected Output:

@tivrfoa
tivrfoa / java-interview-question-using-HashMap.md
Created February 23, 2025 10:37
Prompting ChatGPT: Create a Java interview question where the solution needs to use a HashMap

Java Interview Question: Using HashMap for Frequency Counting

Question:

You are given a list of words, and your task is to find the top N most frequent words in the list. Implement a function that efficiently counts word occurrences and returns the top N words sorted by frequency.

Requirements:

  1. Efficiently count the occurrences of each word.
  2. Retrieve the top N words sorted by frequency.
  3. If two words have the same frequency, they should be sorted alphabetically.
  4. Assume the input is a large dataset, so efficiency matters.
@tivrfoa
tivrfoa / java-interview-question-usuing-enum.md
Created February 23, 2025 10:30
Prompting ChatGPT: Create a Java interview question, where using enum is the best solution

ChatGPT:

Java Interview Question:

Question:
You are designing a system that processes customer orders. Each order has a status that can change over time. The possible statuses are:

  • NEW (Order just created)
  • PROCESSING (Currently being processed)
  • SHIPPED (Sent to the customer)
@tivrfoa
tivrfoa / Grok3-hpack.c
Created February 20, 2025 09:36
Testing Grok 3 - Write an HPACK implementation in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
// --- Data Structures ---
// Header entry structure for static and dynamic tables
typedef struct {