Skip to content

Instantly share code, notes, and snippets.

// Use Ammonite REPL to run this example: https://ammonite.io/
import $ivy.`org.typelevel::cats-core:2.0.0`, cats.syntax.either._, $ivy.`com.chuusai::shapeless:2.3.3`, shapeless._
trait CsvValueDecoder[A] {
def decode(value: String): Either[String, A]
}
object CsvValueDecoder {
def create[A](f: String => Either[String, A]): CsvValueDecoder[A] = (value: String) => f(value)
}
import akka.stream.scaladsl.{Compression, JsonFraming}
import akka.util.ByteString
import org.bson.Document
import akka.stream.scaladsl.{Sink, Source}
val maximumObjectLength = 16000000
s3Client
.download(bucket, fileName)
.via(Compression.gunzip())
.via(JsonFraming.objectScanner(maximumObjectLength))
import akka.stream.scaladsl.{Compression, JsonFraming}
val maximumObjectLength = 16000000
s3Client
.download("backup.bucket", "CookieCollectionBackup")
.via(Compression.gunzip())
.via(JsonFraming.objectScanner(maximumObjectLength))
import akka.stream.scaladsl.Compression
s3Client
.download("backup.bucket", "CookieCollectionBackup")
.via(Compression.gunzip())
s3Client
.download(bucket = "backup.bucket", key = "CookieCollectionBackup")
Source.fromPublisher(collection.find(): Publisher[org.bson.Document])
.map((doc: org.bson.Document) ⇒ doc.toJson())
.map((json: String) ⇒ ByteString(json))
.via(Compression.gzip: Flow[ByteString, ByteString, NotUsed])
.runWith(s3Sink)
val s3Sink: Sink[ByteString, Future[MultipartUploadResult]] =
s3Client.multipartUploadWithHeaders(
bucket = "mycookiesbucket12345",
key = "CookieCollectionBackup.json",
Source.fromPublisher(collection.find(): Publisher[org.bson.Document])
.map((doc: org.bson.Document) ⇒ doc.toJson())
.map((json: String) ⇒ ByteString(json))
.via(Compression.gzip: Flow[ByteString, ByteString, NotUsed])
.runWith(s3Sink)
val s3Sink: Sink[ByteString, Future[MultipartUploadResult]] =
s3Client.multipartUpload(
bucket = "bucketWithCookies",
key = "CookieCollectionBackup.json"
Source.fromPublisher(collection.find(): Publisher[org.bson.Document])
.map((doc: org.bson.Document) ⇒ doc.toJson())
.map((json: String) ⇒ ByteString(json))
.runWith(s3Sink)
val s3Sink: Sink[ByteString, Future[MultipartUploadResult]] =
s3Client.multipartUpload(
bucket = "bucketWithCookies",
key = "CookieCollectionBackup.json"
)
@bszwej
bszwej / echo.js
Last active April 26, 2024 05:22
Pure Node.js echo server, that logs all incoming http requests (method, path, headers, body).
const http = require('http');
const server = http.createServer();
server.on('request', (request, response) => {
let body = [];
request.on('data', (chunk) => {
body.push(chunk);
}).on('end', () => {
body = Buffer.concat(body).toString();