Skip to content

Instantly share code, notes, and snippets.

@tivrfoa
tivrfoa / example1.rs
Created May 18, 2024 13:07
Rust generics trait dyn
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ae0048c018c77abd71b3c5121e02511a
trait Animal {
fn do_sound(&self);
}
struct Dog;
impl Animal for Dog {
fn do_sound(&self) {
println!("hoho");
@tivrfoa
tivrfoa / ai.md
Created May 16, 2024 23:55
Gemini and ChatGPT 3.5 answers to Java C2 megamorphic code #JVM

Question

Regarding Java code:

Let's suppose you have a static method that accepts a few interfaces. Different object instances always call it with a concrete combination of the interfaces, but C2 ends up with megamorphic code. How would you improve that?

ChatGPT 3.5

When you have a static method that accepts interfaces and different object instances call it with various combinations of those interfaces, and you observe megamorphic behavior (where the JVM struggles to optimize due to multiple possible types), you can consider a few strategies to improve performance: >

@tivrfoa
tivrfoa / instructions.md
Created March 16, 2024 01:42 — forked from matthewjberger/instructions.md
Install a nerd font on ubuntu

1.) Download a Nerd Font

2.) Unzip and copy to ~/.fonts

3.) Run the command fc-cache -fv to manually rebuild the font cache

@tivrfoa
tivrfoa / city-jel.txt
Created January 13, 2024 11:36
1brc sin city
jel;18.6
jel;12.8
jel;20.7
jel;13.8
jel;26.7
jel;17.7
jel;24.7
jel;18.4
jel;10.7
jel;21.9
@tivrfoa
tivrfoa / trial1.rs
Created November 30, 2023 00:59
Circular Linked List in Rust
use std::rc::Rc;
use std::cell::RefCell;
#[derive(Debug)]
struct Node {
n: u32,
next: Option<Rc<RefCell<Node>>>,
}
type NodeT = Option<Rc<RefCell<Node>>>;
@tivrfoa
tivrfoa / rust-cell-interior-mutability.rs
Created November 28, 2023 21:02
Rust Cell Interior Mutability
use std::cell::Cell;
#[derive(Debug)]
struct Node {
n: usize,
next: Cell<usize>,
}
fn main() {
let nodes = {
@tivrfoa
tivrfoa / tokio-spawn-await.rs
Last active November 20, 2023 21:53
Rust tokio::spawn await
/*
$ cargo run --release --bin sp1
Finished release [optimized] target(s) in 0.09s
Running `target/release/sp1`
9227465
14930352
24157817
39088169
63245986
102334155
@tivrfoa
tivrfoa / re.rs
Last active November 2, 2023 13:37
Book Beautiful Code - A Regular Expression Matcher
/*
After reading the description:
Character Meaning
c Matches any literal character c.
. (period) Matches any single character.
^ Matches the beginning of the input string.
$ Matches the end of the input string.
* Matches zero or more occurrences of the previous character.
@tivrfoa
tivrfoa / LinkedListBenchmark.java
Created October 12, 2023 21:39
Java LinkedList vs ArrayDeque vs ArrayList
/*
Benchmark Mode Cnt Score Error Units
LinkedListBenchmark.arrayDeque avgt 6 86861,575 ± 6681,783 ns/op
LinkedListBenchmark.arrayList avgt 6 207511,921 ± 20828,824 ns/op
LinkedListBenchmark.linkedList avgt 6 70281,152 ± 9929,807 ns/op
mvn clean verify
java -jar target/benchmarks.jar LinkedListBenchmark
@tivrfoa
tivrfoa / pom.xml
Created June 28, 2023 22:53
Trying to use GraalVM to compile https://github.com/ebarlas/game-of-life-csp #Java #AWT
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>loomtest</groupId>
<artifactId>csp-game-of-life</artifactId>
<packaging>jar</packaging>
<name>CSP Game of Life</name>
<version>1.0.0-SNAPSHOT</version>