Skip to content

Instantly share code, notes, and snippets.

@hochgi
hochgi / Trump.ttl
Last active November 21, 2017 17:27
RDF sample data to demonstrate CM-Well's yg pipe feature
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix locn: <http://www.w3.org/ns/locn#> .
@prefix madsrdf: <http://www.loc.gov/mads/rdf/v1#> .
@prefix geonames: <http://www.geonames.org/ontology#> .
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix xmpl: <http://ont.example.org/2017/v1.0#> .
@prefix time: <http://www.w3.org/2006/time#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@hochgi
hochgi / .gitignore
Last active January 17, 2020 01:22
qotd for CM-Well
# idea stuff
*.iml
.idea/
# scala staff
*.class
*.log
branches.properties
logs
@hochgi
hochgi / FutureOps.scala
Last active July 3, 2018 06:09
Fast dynamic async reduce
implicit class FutureOps(companion: Future.type) {
def unorderedReduce[A, B](in: Iterable[A])
(fn: A => Future[B], combop: (B,B) => B)
(implicit executor: ExecutionContext): Future[B] = {
val promises = Array.fill(2 * in.size - 1)(Promise.apply[B])
var i = 0 // used for iteration optimization (not needing to search for uncompleted promise from start every time)
in.foreach { a =>
fn(a).onComplete { t =>
var p = promises(i)
@hochgi
hochgi / Scheduling.scala
Created February 20, 2019 11:11
scala scheduling with akka
import akka.actor.{ActorSystem, Scheduler}
import com.astoncap.util.concurrent.Async._
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.util.Try
trait Scheduling {
implicit val scheduling: Scheduling = this
@hochgi
hochgi / data-science-bowl-2019.ipynb
Created December 5, 2019 14:20
data-science-bowl-2019 jupyter notebook sandbox
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hochgi
hochgi / LogbackEventLogger.scala
Created October 20, 2020 08:17
implementation of internal event logger lib backed by logback's rolling file appender
package com.sparkbeyond.engine.util.logging.eventslogger
import java.nio.charset.StandardCharsets
import akka.Done
import ch.qos.logback.core.rolling.{
FixedWindowRollingPolicy,
RollingFileAppender,
SizeBasedTriggeringPolicy
}
@hochgi
hochgi / 0.17.19.png
Last active June 13, 2021 17:11
tapir 0.17.19 vs 0.18.0-M15
0.17.19.png
@hochgi
hochgi / Tree.java
Last active June 16, 2021 07:01
Tree parsing exercise java
package scratch.example;
import java.util.List;
public class Tree {
int value;
List<Tree> children;
public Tree(int value, List<Tree> children) {
@hochgi
hochgi / Tree.py
Last active July 27, 2021 13:37
Tree parsing exercise python
from typing import Optional
class Tree:
def __init__(self, value: int, children: list):
self.value = value
self.children = children # list of Tree
def format_tree(t: Tree) -> str:
pass
@hochgi
hochgi / StreamEventInspector.scala
Created July 7, 2021 12:18
akka-streams custom stream inspector
import akka.stream.{Attributes, FlowShape, Inlet, Outlet}
import akka.stream.stage.{GraphStage, GraphStageLogic, InHandler, OutHandler}
import com.typesafe.scalalogging.Logger
object StreamEventInspector {
def default[T](logger: Logger, context: String, printElem: T => String): StreamEventInspector[T] = {
val ctx = "[" + context + "] "
new StreamEventInspector[T](
() => logger.info(ctx + "upstream completed"),
ex => logger.error(ctx + "upstream failure", ex),