Skip to content

Instantly share code, notes, and snippets.

@eyalroth
eyalroth / lambda-code.js
Created November 30, 2022 12:06
AWS Step Functions Batch Process
const _ = require('lodash');
const { mapSeries } = require('bluebird');
// express handler
async (req, res) => {
const sfExecutionIdHeader = req.header('SF-Execution-Id');
const executionId = sfExecutionIdHeader.substring(sfExecutionIdHeader.lastIndexOf(':') + 1);
const ids = await selectIdsFromDb();
const batches = _.chunk(ids, config.get('batch_size'));
@eyalroth
eyalroth / LogbackLoggerConfigurator.scala
Created April 10, 2020 16:41
Log configuration with logback with file-system watcher over the configuration file
package org.myproject.scalaonly
import java.nio.charset.Charset
import java.nio.file.StandardWatchEventKinds.{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY}
import java.nio.file.WatchEvent.Kind
import java.nio.file._
import java.util.concurrent.locks.ReentrantReadWriteLock
import java.util.logging.{Level, LogManager}
import ch.qos.logback.classic.joran.JoranConfigurator
@eyalroth
eyalroth / ResponseScala2-nodocs.scala
Last active February 9, 2020 10:47
Scala3 - nested ADTs example - Response
import scala.util.control.NonFatal
sealed trait Response[+A] {
def returnValue: Option[A]
def map[B](f: A => B): Response[B]
def flatMap[B](f: A => Response[B]): Response[B]
}
import sys
import re
from os import listdir
from os.path import isfile, join
from collections import OrderedDict
RESOURCES_FILE = "resources-enqueue.php"
OUT_FILE_PREFIX = "lang-"
OUT_FILE_SUFFIX = ".js"
@eyalroth
eyalroth / HttpServer.scala
Last active October 17, 2018 14:43
akka-http #2257 - Http server
import java.net.InetSocketAddress
import java.security.{KeyStore, SecureRandom}
import akka.actor.ActorSystem
import akka.http.scaladsl.Http.{HttpServerTerminated, HttpTerminated, ServerBinding}
import akka.http.scaladsl.server.{Route, RouteResult, RoutingLog}
import akka.http.scaladsl.settings.{ParserSettings, RoutingSettings}
import akka.http.scaladsl.{ConnectionContext, Http}
import akka.stream.{ActorMaterializer, ActorMaterializerSettings}
import com.typesafe.scalalogging.StrictLogging
@eyalroth
eyalroth / ServerRoutes.scala
Last active October 17, 2018 14:43
akka-http #2257 - Server routes
import akka.http.scaladsl.server.{Directives, Route}
import com.typesafe.scalalogging.StrictLogging
import scala.concurrent.ExecutionContext
class ServerRoutes(metricsActorRef: ActorRef, cardActorRef: ActorRef, helloActorRef: ActorRef)
extends Pagination with Directives with StrictLogging {
/* --- Methods --- */
@eyalroth
eyalroth / HttpServerAPI.scala
Last active October 17, 2018 14:43
akka-http #2257 - Http API to server
import akka.actor.ActorSystem
import akka.http.scaladsl.client.RequestBuilding
import akka.http.scaladsl.model.{HttpResponse, StatusCodes}
import akka.http.scaladsl.unmarshalling.Unmarshal
import com.typesafe.scalalogging.StrictLogging
import HttpClient
import scala.concurrent.Future
class HttpServerAPI(lowThroughputClient: HttpClient, highThroughputClient: HttpClient)
@eyalroth
eyalroth / HttpClient.scala
Last active October 17, 2018 14:43
akka-http #2257 - Http Client
import akka.actor.ActorSystem
import akka.http.scaladsl.coding.Gzip
import akka.http.scaladsl.model.{HttpRequest, HttpResponse, ResponseEntity, StatusCode}
import akka.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
import akka.http.scaladsl.{ConnectionContext, Http}
import akka.stream._
import akka.stream.scaladsl.{Keep, Sink, Source}
import com.typesafe.scalalogging.StrictLogging
import com.typesafe.sslconfig.akka.AkkaSSLConfig
import javax.net.ssl._
def createNonUniqueOrReturnExisting(name: String)(implicit session: DBSession = DB.autoCommitSession): Long = {
// here lies the query
}
WITH
val (l_name,d_label ) AS
(values
(? , ?)
),
ins AS
( INSERT INTO
label (label_name, device_label)
SELECT l_name, d_label FROM val
ON CONFLICT ON CONSTRAINT label_name_unique DO NOTHING