Skip to content

Instantly share code, notes, and snippets.

Adam Warski adamw

Block or report user

Report or block adamw

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View bootzooka8.scala
val TestConfig: Config = DefaultConfig
.modify(_.email.emailSendInterval)
.setTo(100.milliseconds)
View bootzooka7.scala
def changePassword(userId: Id @@ User,
currentPassword: String,
newPassword: String): ConnectionIO[Unit] =
for {
user <- userOrNotFound(UserModel.findById(userId))
_ <- verifyPassword(user, currentPassword)
_ = logger.debug(s"Changing password for user: $userId")
_ <- UserModel.updatePassword(userId, User.hashPassword(newPassword))
} yield ()
View bootzooka6.scala
object UserModel {
def findById(id: Id @@ User): ConnectionIO[Option[User]] = {
findBy(fr"id = $id")
}
def findByEmail(email: String @@ LowerCased): ConnectionIO[Option[User]] = {
findBy(fr"email_lowercase = $email")
}
private def findBy(by: Fragment): ConnectionIO[Option[User]] = {
View bootzooka5.scala
import io.circe.Decoder
import com.softwaremill.bootzooka.infrastructure.Json._
case class Register_IN(login: String, email: String, password: String)
implicitly[Decoder[Register_IN]]
View bootzooka4.scala
import com.softwaremill.tagging.@@
import io.circe.generic.AutoDerivation
import io.circe.java8.time.{JavaTimeDecoders, JavaTimeEncoders}
import io.circe.{Decoder, Encoder, Printer}
object Json extends AutoDerivation with JavaTimeDecoders with JavaTimeEncoders {
val noNullsPrinter: Printer = Printer.noSpaces.copy(dropNullValues = true)
implicit def taggedStringEncoder[U]: Encoder[String @@ U] =
Encoder.encodeString.asInstanceOf[Encoder[String @@ U]]
View bootzooka3.scala
private val updateUserEndpoint = secureEndpoint.post
.in(User)
.in(jsonBody[UpdateUser_IN])
.out(jsonBody[UpdateUser_OUT])
.serverLogic {
case (authData, data) =>
(for {
userId <- auth(authData)
_ <- userService.changeUser(userId, data.login, data.email).transact(xa)
} yield UpdateUser_OUT()).toOut
View bootzooka2.scala
case class DBConfig(username: String, password: String, url: String,
migrateOnStart: Boolean, driver: String, connectThreadPoolSize: Int) {
override def toString: String =
s"DBConfig($username,***,$url,$migrateOnStart,$driver,$connectThreadPoolSize)"
}
case class HttpConfig(host: String, port: Int)
// ... other config classes ...
case class Config(db: DBConfig, api: HttpConfig, email: EmailConfig,
passwordReset: PasswordResetConfig, user: UserConfig)
View bootzooka1.scala
trait EmailModule extends BaseModule {
lazy val emailService = new EmailService(idGenerator, emailSender, config.email, xa)
// the EmailService implements the EmailScheduler functionality - hence, creating
// an alias for this dependency
lazy val emailScheduler: EmailScheduler = emailService
lazy val emailTemplates = new EmailTemplates()
// depending on the configuration, creating the appropriate EmailSender instance
lazy val emailSender: EmailSender = if (config.email.mailgun.enabled) {
new MailgunEmailSender(config.email.mailgun)(sttpBackend)
} else if (config.email.smtp.enabled) {
View Tender.json
{
"contractName": "Tender",
"abi": [
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
View pool16.scala
val ae = IO.effectAsync[Any, Throwable, Unit] { cb =>
ec3.submit(new Runnable {
override def run(): Unit = {
println(Thread.currentThread().getName + " (async)")
cb(IO.fail(new IllegalStateException()))
}
})
}
run("async shift error") {
You can’t perform that action at this time.