Skip to content

Instantly share code, notes, and snippets.

View MarcoNicolodi's full-sized avatar

Marco Nicolodi MarcoNicolodi

View GitHub Profile
(ns advent-of-code-2020.day4
(:require [clojure.string :as str]
[clojure.set :as set]))
(def path "./resources/day4-input")
(def required-data
#{"byr" "iyr" "eyr" "hgt" "hcl" "ecl" "pid"})
(defn valid-byr? [byr]
(ns advent-of-code-2020.day3
(:require [clojure.string :as str]))
(def path "./resources/day3-input")
(defn wire-vec->map [map-vec]
{:path map-vec
:width (-> map-vec first count)
:height (count map-vec)})
(ns advent-of-code-2020.day2
(:require [clojure.string :as str]))
;;part 1
(def path "./resources/day2-input")
(defn wire->policy+password [path]
(->> path
slurp
str/split-lines
@MarcoNicolodi
MarcoNicolodi / day_3_part_1.clj
Created December 8, 2019 22:48
advent of code day 3 part 1
(ns advent-of-code-2019.day-3
(:require [clojure.string :as str]
[clojure.set :as set]))
(def letter->direction {"R" :right "L" :left "U" :up "D" :down})
(defn str->direction+distance [[dir & dists]]
{:direction (letter->direction (str dir))
:distance (Integer/parseInt (str/join dists))})
@MarcoNicolodi
MarcoNicolodi / day_2.clj
Last active December 7, 2019 17:02
advent of code 2019 day 2
(ns advent-of-code-2019.day-2
(:require [clojure.string :as str]))
(defn halt? [[op & _]] (= op :halt))
(defn pointer+memory->instruction [pointer memory]
(let [int->opcode {1 + 2 * 99 :halt}
op (nth memory pointer)
in1 (nth memory (inc pointer) 0)
in2 (nth memory (+ 2 pointer) 0)
public class Comment
{
public Guid ProposalId { get; }
public Guid UserId { get; }
public string Content { get; private set; }
public Comment(Guid proposalId, Guid userId, string content)
{
if(String.IsNullOrWhiteSpace(content))
throw new DomainException("Empty comments not allowed");
@MarcoNicolodi
MarcoNicolodi / Proposal.cs
Last active November 29, 2019 17:54
Proposal aggregate maintains invariants about comments
public class Proposal
{
private List<Comments> _comments;
public IReadOnlyList<Comments> Comments => _comments.AsReadOnly();
private bool IsOpenForComments => Status == ProposalStatus.Pending;
public Guid CandidateId { get; }
public Guid JobListingId { get; }
public ProposaStatus Status { get; private set; }
public DateTime ClosedAt { get; private set; }
@MarcoNicolodi
MarcoNicolodi / Program.cs
Last active November 29, 2019 16:44
Proposal with access to other aggregates lacks boundaries
var proposal = _proposalRepository.Find(id);
proposal.Candidate.Ban();
proposal.JobListing.AddPreRequisite(PreRequisite.Clojure);
proposalRepository.Save(proposal);
@MarcoNicolodi
MarcoNicolodi / Proprosal.cs
Created November 29, 2019 16:27
Showing different relationships between aggregates
public class Proposal : Entity
{
public Guid CandidateId { get; }
public Guid JobListingId { get; }
}
public class Proposal : Entity
{
public Candidate CandidateId { get; }
public JobListing JobListingId { get; }
@MarcoNicolodi
MarcoNicolodi / Program.cs
Last active November 29, 2019 16:08
Saving a non aggregate root may violate invariants
var inconsistentComment = new Comment(closedProposalId, anyCandidateIdIWant, content);
_commentsRepository.Save(comment);