Skip to content

Instantly share code, notes, and snippets.

View soujiro32167's full-sized avatar
👾
Software is eating the world

Eli Kasik soujiro32167

👾
Software is eating the world
  • Traverse Labs
  • Montreal, QC
View GitHub Profile
<p>A message after post</p>
<script type="text/javascript">
alert('Success!');
</script>
@soujiro32167
soujiro32167 / Main.java
Last active October 31, 2018 21:28
TypeSafe config inclusion pattern
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
class Scratch {
public static void main(String[] args) {
Config config = ConfigFactory.load();
System.out.println(config.getConfig("my"));
}
}
@soujiro32167
soujiro32167 / ReadWriteTest.scala
Last active November 16, 2018 18:21
Spark read write test
package com.byond.sparkperformance
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.{Dataset, SaveMode, SparkSession}
object ReadWriteTest {
def main(args: Array[String]) {
val (file: String, factor: Int) = args match {
case Array(f, fc) => (f, fc.toInt)
case _ => "target/classes/sample.txt"
@soujiro32167
soujiro32167 / index.js
Created December 27, 2018 21:41
Teaching report for CSMB
function zip(a1, a2){if (a1.length > 0 && a2.length > 0) return [[a1.shift(), a2.shift()]].concat(zip(a1, a2)); else return []; };
(function(){
var rows = document.querySelectorAll('form table')[4].querySelectorAll('tr');
var actualRows = [].slice.call(rows, 3, rows.length - 1).filter((r, i) => (i + 1) % 3 != 0);
var mappedRows = actualRows
.map(row => [].slice.call(row.querySelectorAll('td'))
.map(td => td.textContent.trim().replace(/\s/, " ")));
var evenRows = mappedRows.filter((r, i) => i % 2 == 0);
var oddRows = mappedRows.filter((r, i) => i % 2 != 0);
@soujiro32167
soujiro32167 / what-is-my-self.sc
Created October 8, 2019 14:33
Limits of type inference
import io.circe.syntax._
import io.circe._
import io.circe.parser._
import io.circe.generic.semiauto._
import scalaz.NonEmptyList
sealed trait TType {
type Self
}
@soujiro32167
soujiro32167 / DocUtils.scala
Created May 7, 2020 14:29
Extracting a static redoc site from Tapir
import java.nio.file.{ Files, Path, Paths }
import cats.effect.{ ContextShift, IO }
import org.http4s.{ HttpRoutes, Request }
import sttp.tapir.Endpoint
import sttp.tapir.redoc.http4s.RedocHttp4s
import sttp.tapir.openapi.circe.yaml._
import sttp.tapir.docs.openapi._
object DocUtils {
@soujiro32167
soujiro32167 / demo.scala
Last active October 10, 2020 03:35
Http4s: decide response type based on stream head
import cats.effect.IO
import fs2.Stream
import org.http4s.{HttpRoutes, Request, Response}
import org.http4s.dsl.Http4sDsl
import scala.concurrent.ExecutionContext
import scala.util.control.NoStackTrace
val ec = ExecutionContext.global
implicit val cs = IO.contextShift(ec)
@soujiro32167
soujiro32167 / bst.scala
Created December 7, 2020 15:23
Generic binary search tree
sealed trait Tree[+A]
case class Node[A](value: A, left: Tree[A], right: Tree[A]) extends Tree[A]
case object Leaf extends Tree[Nothing]
trait MinMax[A] {
val min: A
val max: A
}
implicit val intMM: MinMax[Int] = new MinMax[Int] {
@soujiro32167
soujiro32167 / aoc16.scala
Created December 20, 2020 01:35
AoC Day 16
package advent
import cats.syntax.all._
object Sixteen extends Inputs:
type Rule = Int => Boolean
type Ticket = List[Int]
type TicketPosition = List[Int -> Int]
def parseRule: String => String \/ Rule = { s =>
@soujiro32167
soujiro32167 / logging.scala
Created March 22, 2021 17:34
Conditional logging in http4s
package com.byond.infinity.sda
import cats.data.{ Kleisli, OptionT }
import cats.effect.{ Resource, Sync }
import org.http4s.{ HttpRoutes, Response }
import cats.syntax.flatMap._
import org.http4s.client.Client
object logging {
val log = org.log4s.getLogger