Skip to content

Instantly share code, notes, and snippets.

View berkes's full-sized avatar
🌱
open to work

Bèr Kessels berkes

🌱
open to work
View GitHub Profile
@berkes
berkes / main.rs
Created October 4, 2022 09:50
instantiator
mod domain {
pub struct EmailAddress {
value: String,
}
impl EmailAddress {
pub fn new(value: String) -> Result<Self, DomainError> {
if value.contains("@") {
Ok(Self { value })
} else {
@berkes
berkes / main.rs
Created October 4, 2022 09:48
Using Value Object
struct PageRequest {
url: String,
size: PageSize,
response_code: HttpResponseCode,
}
//...
PageRequest {
url: "http://example.com/about".to_string(),
size: PageSize::new(1_337)?,
response_code: HttpResponseCode::new(200)?,
@berkes
berkes / main.rs
Created October 4, 2022 09:47
Email as Value Object
#[derive(Debug)]
enum DomainError {
InvalidEmailAddress,
InvalidResponseCode,
}
struct EmailAddress {
value: String,
}
@berkes
berkes / before.rs
Last active October 4, 2022 09:47
Code for Value Objects in Rust blogpost
struct PageRequest {
url: String,
size: usize,
response_code: u16,
}
fn is_valid_email(email: &String) -> bool {
email.contains("@")
}
@berkes
berkes / __filetree
Last active July 5, 2022 15:34
Functional Rails Organisation
✦ ❯ tree test/blog/ app/blog/ lib/
test/blog/
└── posts_test.rb
app/blog/
├── author_posts_query.rb
├── create_post_command.rb
└── post_record.rb
lib/
├── application_cable
│   ├── channel.rb
class MoneyAmount
def initialize(amount_in_cents)
@fractional = fractional
end
def euro
fractional / 100
end
def cents
irb(main):001:1* class Wrapper
irb(main):002:2* def initialize(wrapped)
irb(main):003:2* @wrapped = wrapped
irb(main):004:1* end
irb(main):005:1*
irb(main):006:2* def call(name)
irb(main):007:2* @wrapped.call(name)
irb(main):008:1* end
irb(main):009:0> end
=> :call
@berkes
berkes / HAL-libraries-for-ruby.md
Last active November 4, 2021 13:10
HAL Libraries for Ruby - evaluation

HAL API libraries for Ruby

https://github.com/mikekelly/hal_specification/wiki/Libraries#ruby used as seed.

Evaluation of various HAL clients to build and consume HAL JSON APIs for Plannel. Evaluation purely by reading code and README. No Proof of Concept or experience with any of the libs.

The evaluation was done with a clear goal in mind: build the HTTP+HAL+JSON adapter on an existing business-domain that (hexagonal architecture). Preferably using Sinatra, since this HTTP adapter does not interact with databases or other plumbing etc: only with Models (Root Aggregates) and Commands. Clean, and easy to understand architecture is an important criteria. As are some other criteria: this is very opinionated and might not match what you are looking for, at all: it may very well be that something listed as "con" is a "pro" for you.

Tests for the API need a HAL client, the implementation needs a server. Client and server need not be the same library.

@berkes
berkes / example.php
Created October 8, 2021 11:31
URL shortner without storage
<?php
composer require "tuupola/base85:^1.0"
$url = "https://ultimatemotherfuckingwebsite.com/"
$base85 = new Tuupola\Base85;
$tokenized = $base85->encode($url);
$shortened = "https://big.pm/$tokenized";