Skip to content

Instantly share code, notes, and snippets.

View rjsvaljean's full-sized avatar
❤️

Ratan Sebastian rjsvaljean

❤️
View GitHub Profile
@rjsvaljean
rjsvaljean / delookup.vim
Last active July 11, 2018 09:13
vimscript to look up a German word in a vim file, show the translation and write the translation to a file so you can review
" requirements:
"
" - the `trans` command from https://www.soimort.org/translate-shell/
" - '+python3' in `vim --version`
"
"
" Usage:
"
" Ctrl-l over any word you want to look up. You should see something like 'trollte bedeutet toddled'
" at the bottom of the screen and a file like 'trollte-1531294267.0744178' in ~/lookedup/ with the detailed
scala> Stream.iterate(0)(_ + 1)
res1: scala.collection.immutable.Stream[Int] = Stream(0, ?)
scala> res1.take(10).toList
res2: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
scala> case class State[S, A](f: S => (S, A))
defined class State
// fmap = flatmap
@rjsvaljean
rjsvaljean / Main.scala
Created August 24, 2017 08:08
Script to find distribution of PR age
package rxvl
import java.text.SimpleDateFormat
import org.http4s.client.blaze._
import java.util.Date
import cats.instances.map._
import cats.instances.int._
import cats.instances.tuple._
case class ValidatedT[F[_], +E, +A](run: F[Validated[E, A]])
import cats.Monad
import cats.syntax.flatMap._
object ValidatedT {
implicit def monad[F[_]: Monad, E]: Monad[({type l[a] = ValidatedT[F, E, a]})#l] = new Monad[({type l[a] = ValidatedT[F, E, a]})#l] {
def pure[A](x: A) = ValidatedT(Monad[F].pure(Validated.valid(x)))
def flatMap[A, B](fa: ValidatedT[F, E, A])(f: (A) => ValidatedT[F, E, B]) =
ValidatedT(fa.run.flatMap(_.fold(e => Monad[F].pure(Validated.invalid[E, B](e)), i => f(i).run)))
@rjsvaljean
rjsvaljean / build.sbt
Last active March 25, 2017 17:06
Recursion Schemes from Scratch
name := "typelevel-recursion-schemes-talk"
scalaVersion := "2.11.8"
scalacOptions ++= Seq("-feature", "-language:higherKinds")
@rjsvaljean
rjsvaljean / RecursionSchemesUsingMatryoshka.scala
Last active March 25, 2017 17:06
Recursion Schemes using Matryoshka
package rxvl
import matryoshka._
import matryoshka.data._
import scalaz.{Functor, \/-, -\/}
object AnyListFix {
type T = matryoshka.data.Fix[AnyListF]
def nil: Fix[AnyListF] = Fix[AnyListF](Nil)
@rjsvaljean
rjsvaljean / listpara.scala
Last active February 8, 2017 05:00
type specific paramorphisms
def map[A, B](f: A => B)(as: List[A]): List[B] = {
as match {
case Nil => Nil
case h :: t => f(h) :: map(f)(t)
}
}
def fold[A, B](z: B)(f: (A, B) => B)(as: List[A]): B = {
as match {
@rjsvaljean
rjsvaljean / hlistOfFs.scala
Created September 24, 2016 21:21
For a given F[_], a type level check that the HList L looks like F[A] :: F[B] :: F[C] :: HNil and fails to compile when it looks like F[A] :: SomeOtherType :: HNil
sealed trait IsDataType[F[_], L <: HList]
object IsDataType {
implicit def hnil[F[_]]: IsDataType[F, HNil] = new IsDataType[F, HNil] {}
implicit def rest[F[_], H, T <: HList : ({type l[a] = IsDataType[F, a]})#l]: IsDataType[F, ::[F[H], T]] =
new IsDataType[F, F[H] :: T] {}
}
object Zip {
import java.io._
import java.util.zip._
import org.apache.commons.io.IOUtils
private val logger = LoggerFactory.getLogger(getClass)
private val BUFFER = 2048
def zip(inputDir: File): Option[File] = {
val zipFile = File.createTempFile("zippedArtifact", ".zip")
#!/bin/sh
getOrElse() {
if [ -z "$1" ]
then echo $2
else
echo $1
fi
}