Posts

Showing posts from July, 2021

Builder Pattern in Rust

Image
Builder Pattern is useful when we need to create complex objects(structs in rust case). Also if you want to do a fluent DSL Builder is a useful pattern for that as well. Today I will show how we can implement this Pattern in Rust, so I have a simple POC to show and also a video. So Let's get started! 

Concurrency in Rust

Image
Rust has amazing support for concurrency programming. Today I will cover Mutex, Rc, RefCell, Channels, and Threads. I might make a second post covering the rest of the concepts like Arc. Rust dont have green threads since focus on having zero cost of abstractions. However, using channels we have a powerful abstraction to work with threads. Combined with Rc/Arc and RefCell/Cell we have a good foundation for good concurrency programs. Today I want to share 4 small pocs and 4 videos about Mutex, Rc/RefCell, Threads, and Channels in Rust. Let's get started!

Add trait in Rust

Image
Rust has this interesting trait called Add  which allows us to use the + operator and add 2 structs together. This is very useful for numeric types but also for engineering productivity lets say you are building a DSL for instance or an internal DSL. So I made some implementation and a video - Let's get started!

Closures in Rust

Image
Rust allows us to do functional programming. One important thing in FP is being also to pass functions as parameters and also return functions which are also called high Order Functions. Today I want to share 2 videos and 2 pocs showing how we can do High Order Functions in Rust also you will get currying for free :-). I also will show how we can do closures using traits as well. So Let's get started!

Java Agents

Image
 Java Agents are an interesting capability of the JVM. Agents can either be Static(Load when the java app starts with a special flag) or they can be Dynamic(using the dynamic API from java we can dynamically bind to a specific JVM PID. Agents can be used to run any code before the app starts or even to change the bytecode. The cool thing about agents is the fact that is a runtime thing and we do not need to change the source code of the target app. Agents are similar to Aspects but IMHO much better. Mockito uses mocks in order to test difficult scenarios, pretty much all observability solutions for logs and metrics also have agents. Today I want to share 2 pocs, one using a vanilla java app and doing bytecode manipulation, The second using Spring Boot 2.x and running code forever in a background thread as the app also runs. So Let's get started!

Java Bloom Filter

Image
Bloom Filter is a probabilist data structure, created in the 70s. The data structure is used to test if an element is a member of a Set. False Positives(possible in Set) are possible but False negatives(Definitively not in the set) are not. Who uses Bloom Filters? Apache Cassandra, Google Bigtable, Apache HBase, and Postgress to avoid Disk Lookups. Bloom filters are also used by Akamai CDN to prevent one-hit wonders to hit the disk. Medium use Bloom Filters to avoid recommend articles the user already read to the user. Bing, Squid Proxy, Bitcoin, Ethereum also use Bloom Filters. Today I want to share a simple Bloom Filter implementation in Java. So Let's get started! 

Java Bitwise

Image
Bitwise operations are faster and secure. Highly used in Security/Encryption,  Finite State Machines, Graphics, Comunication over ports/sockets, and Bit Fields. Java has support for: AND, OR, Complement, Signed/Unsigned Right Shift, Signed Left Shift. Java does not have Unsigned Left Shift. Today I want to share a simple POC showing all these operations and understanding them in detail. So Let's get started! 

Simple Dummy Clojure Parser in Rust

Image
This is not a production-ready neither serious parser, it's for pure fun! I was bored during one of the pandemics late nights watching Sam Rose's 3h parser video . So I decided to do something similar, inspired by Sam's video. Of course, I did not want to make a 3 hours video fighting Rust compiler - which is the ultimate reality but something shorter. The code is similar but I have few more operations like * and inc.  I also using a queue for Args not Stack so we can preserve ordering. So this is a cool way to learn rust because in the code we will be using Stack and Queue Data Structures and basics of borrow and ownership in rust. Let's get started!

Vector in Rust

Image
Vector is a core collection in Rust. Vector(Vec) can be used for storing a list of values or even if you need a Stack - it's your data type. Rust language is pretty fast and secure however dealing with borrowing, ownership, and lifespan lifecycle is a high wall that often you can bash your head pretty hard against it. Returning Vecs and passing them as parameters could be pretty challenging if you were new to Rust. Strings also are pretty challenging in Rust. So today I want to share a video doing common operations with Vecs but always using functions and passing Vecs and Receiving Vecs. Hopefully, this will be useful in your common and daily work with Rust. Let's get started!