Skip to content

Instantly share code, notes, and snippets.

View gustavoamigo's full-sized avatar

Gustavo Amigo gustavoamigo

  • Yellow
  • São Paulo, Brasil
View GitHub Profile
@gustavoamigo
gustavoamigo / Rubyist.scala
Last active May 23, 2018 10:30
Ruby like postfix conditionals with Scala
implicit class RicherConditional[T](ifTrue: => T ) {
def unless(condition: Boolean) = new WhenOrOtherwise(!condition, ifTrue)
def when(condition: Boolean) = new WhenOrOtherwise(condition, ifTrue)
}
class WhenOrOtherwise[T] (condition: Boolean, ifTrue: => T) {
def otherwise(ifOtherwise: => T) = if(condition) ifTrue else ifOtherwise
def otherwiseNone = if(condition) Some(ifTrue) else None
}
@gustavoamigo
gustavoamigo / Shakespeare.scala
Created June 24, 2015 19:55
Shakespeare with Dynamic Trait
// Fun with scala.Dynamic http://www.scala-lang.org/api/current/index.html#scala.Dynamic
case object MacBeth extends Dynamic {
def applyDynamic(method: String)(args: Any *) = {
println(s"$method")
MacBeth
}
}
MacBeth itIsATale() toldByAnIdiot() fullOfSoundAndFury() signifyingNothing()
@gustavoamigo
gustavoamigo / ScalaFuture.scala
Last active January 2, 2017 23:07
Example of using explicit execution contexts with Scala Futures to isolate blocking IO.
import java.util.concurrent._
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext, Future}
object FixedThreadPool {
def apply(nThreads: Int, name: String, daemon: Boolean = true): ThreadPoolExecutor =
new ThreadPoolExecutor(nThreads,nThreads,0L,TimeUnit.MILLISECONDS,new SynchronousQueue[Runnable],new NamedThreadFactory(name, daemon))
}
@gustavoamigo
gustavoamigo / ReprocessDeadLetter.java
Created June 29, 2018 21:15
Reprocess SQS Dead Letter Messages AWS
package script;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSClientBuilder;
import com.amazonaws.services.sqs.model.Message;
import com.amazonaws.services.sqs.model.ReceiveMessageRequest;
import com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry;
import java.util.List;
import java.util.UUID;