Skip to content

Instantly share code, notes, and snippets.

View intracer's full-sized avatar

Ilya Korniiko intracer

  • Wikimedia Ukraine
  • Ukraine
View GitHub Profile
@OlegIlyenko
OlegIlyenko / ApolloCacheExtension.scala
Last active February 10, 2022 22:05
Example of Sangria middleware for Apollo Cache Control (https://github.com/apollographql/apollo-cache-control)
import sangria.ast._
import sangria.execution._
import sangria.schema.Context
import sangria.marshalling.queryAst._
import java.util.concurrent.ConcurrentLinkedQueue
import scala.concurrent.duration.FiniteDuration
import scala.collection.JavaConverters._
@lihaoyi
lihaoyi / Test.scala
Created October 30, 2017 13:49
Resolving jars with Coursier and compiling Scala with the Zinc incremental compiler, in a self-contained Ammonite script
import play.api.libs.json.Json
object Main{
def main(args: Array[String]): Unit = {
println(
Json.prettyPrint(
Json.toJson(Seq("Hello", "World", "Cow"))
)
)
}
0: Tue Jun 6 21:03:41 DST 2017: OK
1: Tue Jun 6 21:07:28 DST 2017: OK
2: Tue Jun 6 21:11:15 DST 2017: OK
3: Tue Jun 6 21:15:02 DST 2017: OK
4: Tue Jun 6 21:18:48 DST 2017: OK
5: Tue Jun 6 21:22:39 DST 2017: OK
6: Tue Jun 6 21:26:24 DST 2017: OK
7: Tue Jun 6 21:30:07 DST 2017: OK
8: Tue Jun 6 21:33:49 DST 2017: OK
9: Tue Jun 6 21:37:32 DST 2017: OK
#!/bin/bash
export LANG=C
for ((i=0;1;i++)) ; do
if make -j16 >/dev/null 2>>log.txt ; then
echo "$i: $(date): OK" >>log.txt
else
echo "$i: $(date): NG" >>log.txt
fi
package hello
import java.io.ByteArrayOutputStream
import chisel3._
import chisel3.iotesters.{Driver, PeekPokeTester}
sealed trait Op
object Op{
case class GotoIfZero(dest: Byte, valueAddr: Byte) extends Op
@aaronlevin
aaronlevin / shapeless-arb-keys.scala
Last active May 13, 2016 08:46
Use Structured Keys in Shapeless Records
/**
* Working with shapeless' records is great. However, you are limited to using only String, Integer, Boolean, and
* (package) Objects as singleton keys as the singleton machinery requires a stable point (I don't really fully
* understand this part but I have an intuition). I had asked if there was a way to use a tuple or case-class
* as a key in the shapeless gitter channel and no one really knew.
*
* I was reading the shapeless source for the Witness type and an idea came to mind: since we can use a package Object
* as a key, what if that key extends a trait (an abstract class can work as well)? Can we use those objects as
* singleton keys and access the values specified in the trait?
*
@milessabin
milessabin / shapeless-session.txt
Created April 1, 2016 12:29
shapeless on the Ammonite REPL with no dependencies other than an installed JDK. Many thanks to @przemekpokrywka for the idea, @alxarchambault for Coursier and @li_haoyi for Ammonite.
miles@frege:~$ ./shapeless.sh
Loading...
Welcome to the Ammonite Repl 0.5.2
(Scala 2.11.7 Java 1.8.0_51)
@ val l = 23 :: "foo" :: true :: HNil
l: Int :: String :: Boolean :: HNil = ::(23, ::("foo", ::(true, HNil)))
@
@przemek-pokrywka
przemek-pokrywka / hello-coursier-ammonite-play.sh
Last active May 7, 2016 22:55
Serve a webpage using Play framework with a simple script. Nothing more, than Linux and Java required. Thanks to brilliant work of Alexandre Archambault, @li_haoyi and Play developers.
#!/bin/bash
test -e ~/.coursier/cr || (mkdir -p ~/.coursier && wget -q -O ~/.coursier/cr https://git.io/vgvpD && chmod +x ~/.coursier/cr)
CLASSPATH="$(~/.coursier/cr fetch -q -p \
\
com.typesafe.play:play-netty-server_2.11:2.5.0 \
com.typesafe.play:play_2.11:2.5.0 \
com.lihaoyi:ammonite-repl_2.11.7:0.5.2 \
\
)" java \
-Dplay.crypto.secret=foo.bar.baz \
@crmaxx
crmaxx / undertow.scala
Last active January 4, 2019 13:47 — forked from itang/undertow.scala
import io.undertow.Undertow
import io.undertow.server.HttpHandler
import io.undertow.server.HttpServerExchange
import io.undertow.util.Headers
object server extends App {
val server: Undertow = Undertow.builder().addHttpListener(8080, "localhost").setHandler(new HttpHandler() {
override def handleRequest(exchange: HttpServerExchange): Unit = {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain")
exchange.getResponseSender().send("Hello, world!")
@rklaehn
rklaehn / Client example
Last active June 8, 2020 12:38
akka http file server
package akkahttptest
import akka.http.Http
import akka.stream.ActorFlowMaterializer
import akka.actor.ActorSystem
import akka.stream.scaladsl.{Sink, Source}
import akka.http.model._
object TestClient extends App {