Skip to content

Instantly share code, notes, and snippets.

View MehdiSadeghi1996's full-sized avatar
🌴
On vacation

Mehdi MehdiSadeghi1996

🌴
On vacation
  • Drug Store 4 Bagh
  • Tehran
View GitHub Profile
@MehdiSadeghi1996
MehdiSadeghi1996 / executor.go
Created December 18, 2023 09:51 — forked from daholino/executor.go
Non-blocking sequential processing in Go, infinite (unbounded) buffered channel
package executor
type ExecHandler[T any] func(T)
type Executor[T any] struct {
reader chan T
writer chan T
buffer []T
execHandler ExecHandler[T]
}
@MehdiSadeghi1996
MehdiSadeghi1996 / MethodAttributeC#.cs
Created September 7, 2022 03:47
VALIDATION ATTRIBUTE ON METHOD C#
//Attribute definition
[ValidationAttribute]
[AttributeUsage(AttributeTargets.Parameter)]
public class RequiresNotNullAttribute : Attribute {
public static Exception? TryValidate<T>(T value, [CallerArgumentExpression("value")] string? ArgumentName = default) {
var ret = default(Exception?);
if (value == null) {
ret = new ArgumentNullException(ArgumentName);
}
@MehdiSadeghi1996
MehdiSadeghi1996 / Go Philsophy
Created July 8, 2022 07:47
Don't communicate by sharing memory; share memory by communicating
Let me go simple and to the point here.
Don't communicate by sharing memory.
It is like when your are communicating using threads for example you have to use variables or mutexes to lock memory for not allowing someone to read and write on it until the communication is complete.
Share memory by communicating
In go routines values move on channels rather than blocking the memory, sender notifies receiver to receive from that channel and hence it share memory by communicating with receiver to get from a channel
@MehdiSadeghi1996
MehdiSadeghi1996 / Why EventBus?!
Last active June 29, 2022 04:59
Why We Use EventBus?!!!!
Eventbuses are useful when you don't want components to depend on each other.
Instead of a component having many references to other components,
it can just send Events to an Eventbus and does not have to worry about who will take care of them.
events are interfaces for commiunicate.
@MehdiSadeghi1996
MehdiSadeghi1996 / docker-compose.yml
Created June 17, 2022 11:58
mysql-docker compose
version: '3.3'
services:
db:
image: mysql
restart: always
environment:
MYSQL_DATABASE: 'db'
# So you don't have to use root, but you can if you like
MYSQL_USER: 'sa'
# You can use whatever password you like
@MehdiSadeghi1996
MehdiSadeghi1996 / docker-compose.yml
Created June 17, 2022 11:57
rabbitmq-docker-compose persistence messages/data/configs/logs
version: "3"
services:
rabbitmq:
hostname: "development-rabbit"
image: "rabbitmq:3-management"
ports:
- "5672:5672"
- "15672:15672"
volumes:
- 'rabbitmq_log:/var/log/rabbitmq'
@MehdiSadeghi1996
MehdiSadeghi1996 / golang.txt
Created May 26, 2022 06:22
buffered vs unbuffered
Unbuffered channels block if they are not read from. Buffered channels will not block until they hit capacity.
@MehdiSadeghi1996
MehdiSadeghi1996 / docker-compose.yml
Created May 13, 2022 16:21
Docker compose for elastic stack
version: '3'
services:
elasticsearch:
image: elasticsearch:7.17.3
container_name: elasticsearch
ports:
- "9200:9200"
- "9300:9300"
restart: always
environment: