Skip to content

Instantly share code, notes, and snippets.

@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 {
@tivrfoa
tivrfoa / JavaScript-auto-unwrapping-of-promises-in-async-functions.md
Created February 17, 2025 22:31
JavaScript - Auto-Unwrapping of Promises in `async` Functions

Prompting ChatGPT:

I think the following is a strange behavior in JavaScript:

Promises auto-unwrap, so if you do return a promise for a value from within an async function, you will receive a promise for the value (not a promise for a promise for the value).

function defer(callback) {
  return new Promise(function(resolve) {
    setTimeout(function() {
@tivrfoa
tivrfoa / DeepSeek-R1-distill-llama-70B-types-supported-in-Python-3.md
Created February 12, 2025 10:42
DeepSeek R1 distill llama 70B on groqcloud answer to: what types are supported in Python 3?
Okay, the user just asked, "what types are supported in Python 3?" Looking back at the conversation history, I had previously explained Python 3 in detail, covering its features, advantages, and applications. Now, the user is diving deeper into the specifics of data types.

I need to provide a comprehensive yet clear answer. The user might be a programmer looking to understand the data types available or a student trying to learn Python. They might be working on a project and need to know which types to use in different scenarios.

I should start by categorizing the data types. Maybe separate them into standard types, numeric types, sequence types, mapping types, set types, boolean, NoneType, dictionary views, file types, and others. That way, it's organized and easier to follow.

I should explain each type with examples. For instance, under numeric types, I can mention int, float, complex, and their syntax. For sequences, list, tuple, and string, each with examples. This helps the user see how they'r

@tivrfoa
tivrfoa / garbage-collection-vs-manual-memory-management-chatgpt-answer.md
Created February 9, 2025 12:25
when does Garbage collection is faster than manual memory management?

Garbage collection (GC) can sometimes be faster than manual memory management in specific scenarios due to its ability to optimize allocations, reduce fragmentation, and efficiently manage short-lived objects. Here are some situations where GC outperforms manual memory management:

1. Frequent Short-Lived Object Allocations

  • Languages with GC (e.g., Java, Go, C#) often use generational garbage collection, where short-lived objects are allocated in the "young generation" (or equivalent), which is optimized for fast allocation and collection.
  • Example: In a high-throughput web server, frequent allocation and deallocation of request objects can be handled efficiently by GC with minimal overhead.

2. Avoiding Fragmentation

  • Manual memory management (e.g., malloc/free in C, new/delete in C++) can lead to heap fragmentation, slowing down future allocations.
  • GC-based memory managers often use compaction to reduce fragmentation, leading to **faster allocati
@tivrfoa
tivrfoa / init.lua
Created January 16, 2025 10:54
Neovim init.lua
-- require("config.lazy")
-- Set the leader key
vim.g.mapleader = " "
-- General settings
vim.opt.cc = "120"
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.autoindent = true
@tivrfoa
tivrfoa / comp_multi.rs
Created January 12, 2025 10:13 — forked from kepler-5/comp_multi.rs
Python comprehension proc macro that handles multiple nested for-if-clauses, flattening nested structure
// Python comprehension proc macro that handles multiple nested for-if-clauses, flattening nested structure.
// Example:
//
// let vec_of_vecs = vec![vec![1, 2, 3], vec![4, 5, 6]];
//
// let result = comp![x for vec in vec_of_vecs for x in vec].collect::<Vec<_>>();
// assert_eq!(result, [1, 2, 3, 4, 5, 6]);
//
use proc_macro2::TokenStream as TokenStream2;
@tivrfoa
tivrfoa / developers-future-with-LLMs.md
Created December 16, 2024 00:37
Asking Copilot: as LLMs get better, what will happen to developers?

The landscape for developers will undoubtedly change as large language models (LLMs) continue to improve. Here are a few potential ways this might impact developers:

Increased Productivity

  • Automation of Repetitive Tasks: LLMs can handle boilerplate code, documentation, and basic testing, freeing developers to focus on more complex tasks.
  • Enhanced Code Review: Automated code review tools powered by LLMs can catch bugs, suggest optimizations, and ensure adherence to best practices.
  • Quick Prototyping: Developers can leverage LLMs to rapidly generate and test prototypes, accelerating the development process.

Evolution of Roles

  • Focus on High-Level Design: Developers might spend more time on system architecture, design patterns, and problem-solving, relying on LLMs for implementation details.
  • Interdisciplinary Collaboration: With LLMs handling technical minutiae, developers can work more closely with designers, product managers, and stakeholders to create innovative solutions
@tivrfoa
tivrfoa / Was a Java error to not have unsigned in the language.md
Created December 8, 2024 23:04
Asking ChatGPT: Was a Java error to not have unsigned in the language?

The absence of unsigned integer types in Java is not an error but a design decision made by the language creators. Java deliberately avoids unsigned types to simplify the language and reduce potential sources of bugs and confusion. Let’s delve into the reasons and implications of this choice.


1. Java's Philosophy

Java was designed to be simple, robust, and platform-independent. This simplicity extends to its type system:

  • No Unsigned Types:
    • Java developers chose to omit unsigned types to avoid complications like different behaviors when dealing with arithmetic and bitwise operations on signed vs. unsigned numbers.
    • Removing unsigned types reduces complexity in the language specification and implementation.
@tivrfoa
tivrfoa / prompt.md
Created December 2, 2024 21:32
ChatGPT simplified example of how a priority queue can be implemented in Rust, inspired by the structure of Java's PriorityQueue.

Q: convert the following to Rust: https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/PriorityQueue.java

ChatGPT: Converting the entirety of the Java implementation of PriorityQueue from the OpenJDK to Rust is a significant task due to differences in language paradigms, type systems, and standard libraries. However, I can guide you through the general steps and provide a simplified example of how a priority queue can be implemented in Rust, inspired by the structure of Java's PriorityQueue.


Step-by-Step Plan

  1. Understand the Java Code: