Skip to content

Instantly share code, notes, and snippets.

View chadselph's full-sized avatar

Chad Selph chadselph

View GitHub Profile
@chadselph
chadselph / ReadData.scala
Created February 3, 2023 02:02
Reading data from confluent schema registry without using their library
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.common.serialization.{Deserializer, StringDeserializer}
import org.apache.kafka.common.utils.ByteUtils
/**
* Not recommended for production but useful when you want to write some kind of
* quick script that reads data off kafka.
*/
object ReadData {
@chadselph
chadselph / Server.java
Created April 29, 2021 00:43
ugly ftp2http server
package com.goswiftly.http2ftp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.util.Base64;
import static spark.Spark.*;
@chadselph
chadselph / Deserializers.java
Created May 4, 2020 21:32
jackson Deserializer.tryInOrder
package com.goswiftly.services.gtfspoller.jacksonutil;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import io.vavr.control.Try;
import java.util.NoSuchElementException;
public class Deserializers {
@chadselph
chadselph / compare_schemas.py
Created April 18, 2020 18:15
Compare two db schemas
from typing import Generator, Tuple, Set, List
from sqlalchemy import inspect, create_engine
import sys
GeneratorOfDiscrepancies = Generator[Tuple[str, str], None, None]
class InspectorWrapper:
def __init__(self, url: str):
@chadselph
chadselph / Election.scala
Created December 19, 2018 01:13
Choice voting election
package domain
case class Choice(name: String) extends AnyVal
case class Ballot(topChoice: Choice, next: List[Choice]) {
def eliminateChoice(choice: Choice): Option[Ballot] =
if (topChoice == choice) {
next match {
case Nil => None
@chadselph
chadselph / Test.scala
Created March 29, 2017 02:58
trying to convert HList to List[LUB]
import shapeless.{::, HList, HNil}
import shapeless.LUBConstraint._
import shapeless.ops.hlist.ToTraversable._
import scala.util.Try
import shapeless.ops.hlist._
object Path {
def /(s: String) = Path(PathLiteral(s) :: HNil)
@chadselph
chadselph / sleepyrun.py
Created January 11, 2017 01:44
run commands interspersed with sleep
import sys
import argparse
import time
from subprocess import call
parser = argparse.ArgumentParser(description='Run a command for every line in a file, slowly.')
parser.add_argument('-s', type=float, help="Amount of seconds to sleep between commands", default=1.0)
parser.add_argument('file', type=file)
parser.add_argument('prefix', nargs=argparse.REMAINDER)
@chadselph
chadselph / TaskQueue.scala
Last active January 6, 2017 06:04
tiny slick-based distributed task queue prototype
import java.sql.Timestamp
import java.time.{Duration, Instant}
import slick.driver.JdbcProfile
import slick.profile.SqlProfile.ColumnOption.Nullable
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
/**
@chadselph
chadselph / AkkaHttpHeaderExtractor.scala
Last active July 3, 2022 16:04
akka-http directive for opentracing.io
import java.util
import java.util.Map.Entry
import akka.http.scaladsl.model.HttpHeader
import io.opentracing.propagation.TextMap
import scala.collection.JavaConverters.asJavaIteratorConverter
/**
* Used to extract an iterator of Entry[String, String] to the
@chadselph
chadselph / ApiFormats.scala
Last active November 8, 2016 02:28
trying to pass along the type of a PathMatcher to a abstract Route member
package gist.chadselph
import akka.http.scaladsl.server.PathMatcher
import akka.http.scaladsl.server._
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.util.ApplyConverter
/**
* Created by chad on 11/4/16.
*/