Skip to content

Instantly share code, notes, and snippets.

View Akii's full-sized avatar
🚀
To the Moon

Akii

🚀
To the Moon
View GitHub Profile
<?php
class ValueObject {
protected $value;
public function equals(ValueObject $other) {
return $this->value === $other->value;
}
@Akii
Akii / whut.scala
Last active February 14, 2016 16:24
def initiateRegistration(userName: UserName, emailAddress: EmailAddress): Reader[RegistrationRepository, Future[Registration]] = Reader { repo =>
val exists: OptionT[Future, (Registration, Registration)] = for {
e <- repo.findByUserName(userName)
u <- repo.findByEmailAddress(emailAddress)
} yield (e, u)
exists.run.flatMap {
case None =>
val hash = Random.alphanumeric take 32 mkString ""
val reg = Registration(UUID.randomUUID(), userName, emailAddress, hash, DateTime.now())
def listTuple1(List a): Option[(a,a)] = a match {
case x :: y :: _ => Some((x,y))
case _ => None
}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
module Main where
import Projectable
data CounterEvent = Created | Increased | Decreased deriving (Show)
data Counter = Counter Int deriving (Show)
import Data.List (foldl')
data Projection s e = Projection { runProjection :: s -> e -> s
, state :: s
}
mkProjection :: (s -> e -> s) -> s -> Projection s e
mkProjection = Projection
loadProjection :: (s -> e -> s) -> s -> [e] -> Projection s e
/**
* @var DateTimeImmutable <-- kay
*/
private $date;
protected function __construct()
{
$this->date = date("Y-m-d H:i:s"); // <-- waaaat?
}
@Akii
Akii / func_deps.hs
Created January 3, 2017 17:01
Querying an event store with types
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Test2 where
import Data.Aeson
import Data.Maybe (catMaybes)
<?php
$data = [
'req_url' => $_SERVER['REQUEST_URI'],
'remote_addr' => $_SERVER['REMOTE_ADDR'],
'time' => (new DateTime())->format('Y-m-d H:i:s'),
'get' => $_GET,
'post' => $_POST
];
-- pokeNameLine is "Mimikyu @ Ghostium Z \n" (where \n represents newline)
pokeNameLineParser :: Parser (String,String)
pokeNameLineParser = do
name <- manyTill anyChar (spaces <* char '@' *> spaces)
thingAfterAt <- manyTill anyChar newline
return (name, thingAfterAt)