Skip to content

Instantly share code, notes, and snippets.

View erikvanoosten's full-sized avatar

Erik van Oosten erikvanoosten

View GitHub Profile
@erikvanoosten
erikvanoosten / gist:1059045
Created July 1, 2011 17:40
Example of a specs2 unit test, with mocks and rich context
import org.specs2.mutable._
import org.specs2.mock._
import org.specs2.specification.Scope
class ParentElementStrategyTest extends SpecificationWithJUnit with Mockito {
"The ParentElementStrategy" should {
"extract a user ref" in new SimpleContext {
val testColumn = mock[Column]
registry.get("urn:grons.nl:user:9475877") returns testColumn
userStrategy("user").getShardForEntity(ad, columns) must beTheSameAs(testColumn)
@erikvanoosten
erikvanoosten / gist:3604873
Last active October 10, 2015 00:38
Sentries example usage
class DoItAllService extends nl.grons.sentries.support.SentrySupport {
val dbSentry = sentry("mysql:localhost:3366") withMetrics withFailLimit(failLimit = 5, retryDelay = 500 millis)
val twitterApiSentry = sentry("twitter") withMetrics withFailLimit(failLimit = 5, retryDelay = 500 millis) withConcurrencyLimit(3)
def loadTweetFromDb(id: Long): Tweet = dbSentry {
database.load(id)
}
def getFromTwitter(id: Long): Tweet = twitterApiSentry {
TIMECAPSULE_IP="" # e.g. "192.168.1.100"
TIMECAPSULE_VOLUME="/Time Capsule" # also try "/Data"
export PASSWD='YOURPASSWORDHERE' # No need to escape anything (except "'")
MOUNT_POINT="/mnt/timecapsule" # no need to create the directory
IS_MOUNTED=`mount 2> /dev/null | grep "$MOUNT_POINT" | cut -d' ' -f3`
TIMECAPSULE_PATH="//$TIMECAPSULE_IP$TIMECAPSULE_VOLUME"
if [[ "$IS_MOUNTED" ]] ;then
umount $MOUNT_POINT
#!/bin/sh
# one way (older scala version will be installed)
# sudo apt-get install scala
#2nd way
sudo apt-get remove scala-library scala
wget www.scala-lang.org/files/archive/scala-2.10.3.deb
sudo dpkg -i scala-2.10.3.deb
sudo apt-get update
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.*;
import com.yammer.metrics.reporting.GraphiteReporter;
import com.yammer.metrics.reporting.SocketProvider;
import com.yammer.metrics.stats.Snapshot;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/**
@erikvanoosten
erikvanoosten / Parboiled2CsvParser.scala
Created September 23, 2015 11:37 — forked from maciej/Parboiled2CsvParser.scala
Parboiled2 CSV parser
/* based on comments in https://github.com/sirthias/parboiled2/issues/61 */
case class Parboiled2CsvParser(input: ParserInput, delimeter: String) extends Parser {
def DQUOTE = '"'
def DELIMITER_TOKEN = rule(capture(delimeter))
def DQUOTE2 = rule("\"\"" ~ push("\""))
def CRLF = rule(capture("\n\r" | "\n"))
def NON_CAPTURING_CRLF = rule("\n\r" | "\n")
val delims = s"$delimeter\r\n" + DQUOTE

Keybase proof

I hereby claim:

  • I am erikvanoosten on github.
  • I am erikvanoosten (https://keybase.io/erikvanoosten) on keybase.
  • I have a public key ASAGx3KiQYeMb9TXRsaSLpS2XNt6-W2zd-d9XV1nT72G2Ao

To claim this, I am signing this object:

@erikvanoosten
erikvanoosten / RuntimeReproducer.scala
Created April 8, 2023 05:47
Reproduces problem where a ZIO taks runs on another thread than expected
import zio.internal.ExecutionMetrics
import zio.{Executor, Runtime, RuntimeFlag, RuntimeFlags, Scope, Task, Trace, Unsafe, ZIO, ZIOAppArgs, ZIOAppDefault, ZLayer}
object RuntimeReproducer extends ZIOAppDefault {
override def run: ZIO[Any with ZIOAppArgs with Scope, Any, Any] =
for {
runtime <- ZIO.runtime[Any]
_ <- ZIO.attempt {
println("main thread id" + Thread.currentThread().getId)
package test
import zio._
import zio.stream.ZStream
import zio.internal.ExecutionMetrics
object MinimalReproducer extends ZIOAppDefault {
/**
* A runtime layer that can be used to run everything on the thread of the caller.
package zio.kafka.example
import io.github.embeddedkafka.{ EmbeddedK, EmbeddedKafka, EmbeddedKafkaConfig }
import org.apache.kafka.clients.producer.ProducerRecord
import zio._
import zio.kafka.consumer.Consumer.AutoOffsetStrategy
import zio.kafka.consumer.{ Consumer, ConsumerSettings, OffsetBatch, Subscription }
import zio.kafka.producer.{ Producer, ProducerSettings }
import zio.kafka.serde.Serde
import zio.logging.backend.SLF4J