Skip to content

Instantly share code, notes, and snippets.

View lordcodes's full-sized avatar
⌨️
Coding

Andrew Lord lordcodes

⌨️
Coding
View GitHub Profile
@lordcodes
lordcodes / build.gradle.kts
Created February 16, 2020 21:32
Code for the article: "Protecting secrets in an Android project"
fun Project.propertyOrEmpty(name: String): String {
val property = findProperty(name) as String?
return property ?: environmentVariable(name)
}
fun environmentVariable(name: String) = System.getenv(name) ?: ""
@lordcodes
lordcodes / build.gradle.kts
Created February 16, 2020 21:31
Code for the article: "Protecting secrets in an Android project"
defaultConfig {
buildConfigField(
"String",
"AUTH_CLIENT_SECRET",
buildConfigProperty("GameCatalogueApp_AuthClientSecret")
)
resValue(
"string",
"pusher_key",
@lordcodes
lordcodes / build.gradle.kts
Last active February 16, 2020 21:30
Code for the article: "Protecting secrets in an Android project"
signingConfigs {
create("upload") {
storePassword = propertyOrEmpty(
"GameCatalogueApp_UploadKeystore_KeyPassword"
)
}
}
fun Project.propertyOrEmpty(name: String): String {
val property = findProperty(name) as String?
@lordcodes
lordcodes / gradle.properties
Created February 16, 2020 21:28
Code for the article: "Protecting secrets in an Android project"
GameCatalogueApp_UploadKeystore_KeyPassword=aaaabbbbcccc
GameCatalogueApp_AuthClientSecret=123456789
GameCatalogueApp_Pusher_APIKey=ksldjalksdjskald
@lordcodes
lordcodes / TinyTypes.kt
Created February 11, 2020 07:29
Code for my article "Enforcing type safety of IDs in Kotlin"
data class MessageId(val raw: UUID)
data class ChatId(val raw: String)
data class PersonId(val raw: Long)
@lordcodes
lordcodes / Identifier.kt
Created February 11, 2020 07:27
Code for my article "Enforcing type safety of IDs in Kotlin"
val Identifier<UUID>.uuidString: String
get() = rawValue.toString()
@lordcodes
lordcodes / Team.kt
Last active February 11, 2020 07:28
Code for my article "Enforcing type safety of IDs in Kotlin"
fun Team.inviteMember(id: MemberId) {}
// ❌ Compile error: Type mismatch.
team.inviteMember(team.id)
// ✅ Compiles.
team.inviteMember(member.id)
@lordcodes
lordcodes / Team.kt
Last active February 11, 2020 07:28
Code for my article "Enforcing type safety of IDs in Kotlin"
// Team.kt
typealias TeamId = Identifier<Team, UUID>
data class Team(val id: TeamId)
@lordcodes
lordcodes / Generics.kt
Last active February 11, 2020 07:29
Code for my article "Enforcing type safety of IDs in Kotlin"
data class Identifier<EntityT, RawT>(
val rawValue: RawT
)
data class Room(val id: Identifier<Room, UUID>)
data class Meeting(val id: Identifier<Meeting, UUID>)
fun bookMeeting(id: Identifier<Meeting, UUID>) {}
// ❌ Compile error: Type mismatch.
@lordcodes
lordcodes / Identifier.kt
Last active February 11, 2020 07:29
Code for my article "Enforcing type safety of IDs in Kotlin"
data class Identifier<RawT>(val rawValue: RawT)