Skip to content

Instantly share code, notes, and snippets.

View AhmedMourad0's full-sized avatar
🐧
Farming Penguins

Ahmed Mourad AhmedMourad0

🐧
Farming Penguins
View GitHub Profile
@AhmedMourad0
AhmedMourad0 / InfixToPrefixConverter.py
Last active November 10, 2019 19:48
For college.
from Stack import Stack
def is_operand(token):
"""
checks if token consists completely of digits or letters
:return: true if token is either all digit or all letters (case insensitive), false otherwise
"""
return token.isalpha() or token.isdigit()
@AhmedMourad0
AhmedMourad0 / basic-value-based-example.kt
Last active September 10, 2020 00:05
Code snippets for the `value-based classes and error-handling` Medium article.
data class Password private constructor(val value: String) {
companion object {
fun of(value: String): Password? {
return if (value.isAGoodPassword()) Password(value) else null
}
}
}
@AhmedMourad0
AhmedMourad0 / value-based-adt-example.kt
Last active August 12, 2020 17:48
Code snippets for the `value-based classes and error-handling` Medium article.
data class Password private constructor(val value: String) {
companion object {
fun of(value: String): Either<Violation, Password> {
return when {
value.isTooShort() -> Violation.PasswordTooShort(MIN_LENGTH).left()
value.containsNoNumbers() -> Violation.PasswordContainsNoNumbers.left()
else -> Password(value).right()
}
}
}
@AhmedMourad0
AhmedMourad0 / value-based-exceptions-example.kt
Created August 12, 2020 01:47
Code snippets for the `value-based classes and error-handling` Medium article.
data class Password private constructor(val value: String) {
companion object {
fun of(value: String): Password {
return when {
value.isTooShort() -> throw PasswordTooShortException()
value.containsNoNumbers() -> throw PasswordContainsNoNumbersException()
else -> Password(value)
}
}
}
@AhmedMourad0
AhmedMourad0 / value-based-adt-list-example.kt
Created August 12, 2020 17:58
Code snippets for the `value-based classes and error-handling` Medium article.
data class Password private constructor(val value: String) {
companion object {
fun of(value: String): Either<List<Violation>, Password> {
val violations = buildList {
if (value.isTooShort()) { add(Violation.PasswordTooShort(MIN_LENGTH)) }
if (value.containsNoNumbers()) { add(Violation.PasswordContainsNoNumbers) }
}
return if (violations.isEmpty()) Password(value).right() else violations.left()
}
}
@AhmedMourad0
AhmedMourad0 / value-based-copy-example.kt
Last active September 4, 2020 00:39
Code snippets for the `value-based classes and error-handling` Medium article.
val password = Password.of("Some34Really434Hard21Password!").orThrow() //Throw on violation just for demonstration
val haha = password.copy(value = "gotcha")
@AhmedMourad0
AhmedMourad0 / value-based-adt-list-with-nocopy-example.kt
Created September 5, 2020 01:05
Code snippets for the `value-based classes and error-handling` Medium article.
@NoCopy
data class Password private constructor(val value: String) {
companion object {
fun of(value: String): Either<List<Violation>, Password> {
val violations = buildList {
if (value.isTooShort()) { add(Violation.PasswordTooShort(MIN_LENGTH)) }
if (value.containsNoNumbers()) { add(Violation.PasswordContainsNoNumbers) }
}
return if (violations.isEmpty()) Password(value).right() else violations.left()
}
@AhmedMourad0
AhmedMourad0 / value-based-copy-unresolved-example.kt
Created September 5, 2020 01:11
Code snippets for the `value-based classes and error-handling` Medium article.
val password = Password.of("Some34Really434Hard21Password!").orThrow() //Throw on violation just for demonstration
val haha = password.copy(value = "gotcha") //Unresolved reference: copy
@AhmedMourad0
AhmedMourad0 / build.gradle
Created May 11, 2021 21:38
Idea plugin build.gradle
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id "org.jetbrains.intellij" version "0.7.3"
id "org.jetbrains.kotlin.jvm"
}
repositories {
mavenCentral()
maven {
import com.dequeue.app.common.log
import com.dequeue.app.common.logging.D
import io.ktor.client.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.client.plugins.resources.*
import io.ktor.serialization.kotlinx.json.*
fun ktorHttpClient(baseUrl: String): HttpClient = ktorClient {