Skip to content

Instantly share code, notes, and snippets.

View wedens's full-sized avatar

wedens wedens

  • the middle of nowhere
View GitHub Profile
@wedens
wedens / .zshrc
Created November 9, 2012 04:58
kill all tomcat instances
killtom() {
pid=$(ps aux | grep apache-tomcat | grep 'bin/java' | grep -v grep | awk '{print $2}')
if [ -z "$pid" ]
then
echo "Tomcat is not running!"
else
echo "Killing Tomcat PID: $pid"
kill -9 $pid
fi
}
import scala.reflect.macros.Context
import scala.language.experimental.macros
import scala.annotation.StaticAnnotation
object builderMacro {
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
import Flag._
val optType = typeOf[Option[Any]]
@wedens
wedens / gist:b968e4b9a403ce136c64
Last active August 29, 2015 14:24
two free monads
object FreeCoproduct {
import scalaz._, Scalaz._
import shapeless._
import ops.coproduct.{Inject, Selector}
import Shapoyo._
import Free._
sealed trait Test1Op[A]
case object Test1Alg extends Test1Op[Int]
21:14 <edwardk> in scala you could have working coindexed prisms
21:20 <wedens> edwardk: interesting. do you have a gist? is inference the only problem?
21:20 <edwardk> not handy
21:21 <edwardk> the issue is that we want indexed lenses / traversals to downgrade to normal lenses / traversals right?
21:21 <edwardk> well
21:21 <edwardk> to do that (.) unifies 'p' in the second indexed lens you compose with with (->) in the one upstream
21:21 <edwardk> :t traversed
21:21 <lambdabot> (Applicative f1, Traversable f, Indexable Int p) => p a (f1 b) -> f a -> f1 (f b)
21:21 <edwardk> :t traversed.traversed
21:21 <lambdabot> (Applicative f1, Traversable f, Traversable f2, Indexable Int p) => p a (f1 b) -> f (f2 a) -> f1 (f (f2 b))
@wedens
wedens / x.scala
Last active August 31, 2019 21:26
Codensity and ContT resource management
object test {
val x = for {
_ <- new Codensity[IO, Unit] {
def apply[B](f: Unit => IO[B]): IO[B] =
f(()).ensuring(IO.putStrLn("finally"))
}
a <- new Codensity[IO, Int] {
def apply[B](f: Int => IO[B]): IO[B] =
(IO.putStrLn("acquire: 1") >| 1)
.bracket(x => IO.putStrLn(s"release: $x"))(f)
import fs2.Task
import cats.implicits._
import doobie.imports._
import doobie.free.{databasemetadata => DMD}
package object migrations {
case class TableDesc(
catalog: Option[String],
schema: Option[String],
name: String
sealed trait Error[E, A]
object Error {
case class ThrowError[E, A](error: E) extends Error[E, A]
implicit def monadError[E, S[_]: Functor](implicit I: Inject[Error[E, ?], S]): MonadError[Free[S, ?], E] =
new MonadError[Free[S, ?], E] {
def pure[A](a: A) = Free.pure(a)
def raiseError[A](e: E) = Free.inject[Error[E, ?], S](ThrowError(e))
def handleErrorWith[A](fa: Free[S, A])(f: E => Free[S, A]) =
fa.fold(
@wedens
wedens / polymode-scala.el
Last active August 7, 2019 10:05
full sql-mode in doobie interpolators
(use-package polymode
:commands poly-scala-mode
:mode ("\\.scala\\'" . poly-scala-mode)
:config
(define-hostmode poly-scala-hostmode
:protect-syntax nil
:protect-font-lock t
:mode 'scala-mode)
(define-innermode poly-scala-sql-multiline-innermode
@wedens
wedens / BiMap.scala
Created November 28, 2019 14:59
bimap scala
import cats.Order
import scala.collection.SortedMap
/**
* A data structure representing a bidirectional mapping between
* two key types. Each value in the bimap is associated with exactly
* one value of the opposite type.
*/
final case class BiMap[A, B](ab: SortedMap[A, B], ba: SortedMap[B, A]) { self =>
// TODO: remove unsafe constructor ^^^