Skip to content

Instantly share code, notes, and snippets.

View andriesfc's full-sized avatar

Andries andriesfc

  • Real Estate Development Interactive
  • Cape Town
  • 05:54 (UTC +02:00)
View GitHub Profile
@andriesfc
andriesfc / multiple_ssh_keys.md
Created March 5, 2024 19:04 — forked from mjrulesamrat/multiple_ssh_keys.md
How to Setup Multiple Ssh Keys for Multiple Github/Bitbucket accounts

How to Setup Multiple Ssh Keys for Multiple Github/Bitbucket accounts

create the SSH keys.

ssh-keygen -t rsa -b 4096 -C "mjrulesamrat@gmail.com"

Add the SSH Keys to the SSH-Agent

@andriesfc
andriesfc / eventsoverlapping.kt
Created June 1, 2022 06:54
Collecting events with overlapping dates
import java.time.LocalDate
data class Event(val id: Int, val startDate: LocalDate, val endDate: LocalDate, val name: String)
fun LocalDate(string: String): LocalDate = LocalDate.parse(string)
fun Event.overlap(another: Event): Boolean {
// this:------(start)----------------(end)---------------------->
@andriesfc
andriesfc / mergewindow.kt
Created May 31, 2022 09:34
Process list with merge function
fun <T> MutableList<T>.processWindowWith(
withinWindow: (List<T>, T) -> Boolean,
process: (MutableList<T>) -> Unit,
): MutableList<T> {
if (isEmpty()) {
return this
}
@andriesfc
andriesfc / sample_test.go
Created September 23, 2021 09:20
Ginko test setup and teardown
var _ = Describe("When reading a book", func() {
var book *books.Book // Given
// Setup
BeforeEach(func() {
book = books.New("The Chronicles of Narnia", 300)
Expect(book.CurrentPage()).To(Equal(1))
Expect(book.NumPages()).To(Equal(300))
})
@andriesfc
andriesfc / WalkException.kt
Created September 9, 2020 14:14
Quickly walk an exception tree in kotlin
fun Exception.findDomainError(): JsonObject? {
val stack = generateSequence(this as Throwable) { throwable -> throwable.cause }
val statusRuntimeException = stack.firstOrNull { it is StatusRuntimeException }
?.let { it as StatusRuntimeException }
?: return null
val jsonString = statusRuntimeException.trailers[domainErrorKey] ?: return null
val jsonParser = JsonParser()
return jsonParser.parse(jsonString).asJsonObject
}