Skip to content

Instantly share code, notes, and snippets.

View jivimberg's full-sized avatar

Juan Ignacio Vimberg jivimberg

View GitHub Profile
@jivimberg
jivimberg / CoroutinesUtils.kt
Last active October 11, 2023 00:16
SQS Consumer using Kotlin coroutines and pool of workers.
package com.jivimberg.sqs.published
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.isActive
import kotlinx.coroutines.yield
import java.lang.Thread.currentThread
suspend fun CoroutineScope.repeatUntilCancelled(block: suspend () -> Unit) {
while (isActive) {
class Person() {
private lateinit var _other: Person
private constructor(_other: Person) : this() {
this._other = _other
}
val other: Person
get() {
if (!::_other.isInitialized) {
@jivimberg
jivimberg / takeWhileInclusive.kt
Last active December 18, 2020 10:36
Inclusive implementation of takeWhile for Kotlin. Inspired from this gist: https://gist.github.com/matklad/54776705250e3b375618f59a8247a237 . Read more about this implementation on my blog: https://jivimberg.io/blog/2018/06/02/implementing-takewhileinclusive-in-kotlin/
// kotlin.collections
inline fun <T> Array<out T>.takeWhileInclusive(
predicate: (T) -> Boolean
): List<T> {
var shouldContinue = true
return takeWhile {
val result = shouldContinue
shouldContinue = predicate(it)
result
@jivimberg
jivimberg / build.gradle
Created April 27, 2018 05:47
Jacoco on Gradle - How to verify coverage with exclusions - WRONG
jacocoTestCoverageVerification {
violationRules {
rule {
excludes = [
'com/example/my/package/*',
'com/example/service/MyApplication.kt',
'com/google/protobuf/*'
]
limit {
minimum = 0.79
@jivimberg
jivimberg / build.gradle
Created April 27, 2018 03:02
Jacoco on Gradle - How to verify coverage with exclusions
jacocoTestCoverageVerification {
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
'com/example/my/package/*',
'com/example/service/MyApplication.kt',
'com/google/protobuf/*'
])
})
}
@jivimberg
jivimberg / build.gradle
Last active April 27, 2018 02:25
Jacoco on Gradle - How to verify coverage
apply plugin: "jacoco”
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.79
}
}
}
fun fetchMergeRequestsChannel(gitLabService: GitLabService, lastProductionSha: String): ReceiveChannel<MergeRequest> {
return produce {
var page = 1
while (true) {
gitLabService.delayedFetchMergeRequests(page++).forEach { send(it) }
}
}.takeWhile { it.commitSha != lastProductionSha }
}
fun main(args: Array<String>) {
@jivimberg
jivimberg / unreadCount.gs
Created January 18, 2017 16:31
Google Apps Script to get notified about the number of unread emails in an inbox
function unreadCount() {
var unreadCount = GmailApp.getInboxUnreadCount();
var masterEmail = "<[email protected]>";
var subject = "Your unread count";
var message = "You have " + unreadCount + " emails"
MailApp.sendEmail(masterEmail, subject, message);
}
@jivimberg
jivimberg / sendForm.gs
Created January 3, 2017 07:18
Email Google Form daily full script
function sendFormEmail() {
var toEmailAddress = "[email protected]";
var htmlMessage = HtmlService.createHtmlOutputFromFile("Name-of-your-HTML-file.html").getContent();
var subject = "Subject";
var message = "Some message";
MailApp.sendEmail(toEmailAddress, subject, message, {
htmlBody: htmlMessage
});
}
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.5.0/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH