Skip to content

Instantly share code, notes, and snippets.

View matfournier's full-sized avatar

matfournier matfournier

View GitHub Profile
@matfournier
matfournier / notes.md
Created April 3, 2020 04:14
scaladoc in doom emacs
@matfournier
matfournier / ex.scala
Created March 29, 2020 23:23
Wrapping legacy blocking / context shift / blocker
trait Statsd[F[_]] {
def inc(key: String, magnitude: Int = 1, sampleRate: Double = 1.0): F[Unit]
def dec(key: String, magnitude: Int = 1, sampleRate: Double = 1.0): F[Unit]
def gauge(key: String, magnitude: Double, sampleRate: Double = 1.0): F[Unit]
def timer(key: String, value: Int, sampleRate: Double = 1.0): F[Unit]
}
object Statsd {
def apply[F[_]](implicit F: Statsd[F]): Statsd[F] = F
}
@matfournier
matfournier / ex.scala
Last active March 29, 2020 22:41
Legacy Context Shfit Example
trait Statsd[F[_]] {
def inc(key: String, magnitude: Int = 1, sampleRate: Double = 1.0): F[Unit]
def dec(key: String, magnitude: Int = 1, sampleRate: Double = 1.0): F[Unit]
def gauge(key: String, magnitude: Double, sampleRate: Double = 1.0): F[Unit]
def timer(key: String, value: Int, sampleRate: Double = 1.0): F[Unit]
}
// the legacy client takes in a fixed thread pool of 1. Under the hood it does some
// websocket / NIO stuff
// am I wrong to contextShift onto the same thread pool that it's using?
@matfournier
matfournier / crawl.rc
Created March 2, 2020 06:18
crawl.rc
##### Crawl Init file ###############################################
# For descriptions of all options, as well as some more in-depth information
# on setting them, consult the file
# options_guide.txt
# in your /docs directory. If you can't find it, the file is also available
# online at:
# https://github.com/crawl/crawl/blob/master/crawl-ref/docs/options_guide.txt
#
# Crawl uses the first file of the following list as its option file:
# * init.txt in the -rcdir directory (if specified)
@matfournier
matfournier / blah.el
Created January 14, 2020 18:44
emacs scala lsp
(map! :map scala-mode-map
"C-c C-t" #'lsp-ui-doc-show ;; shows type under cursor as a hover
"C-c t" #'lsp-describe-thing-at-point ;; shows type under cursor in temp buffer below
"C-c H" #'lsp-ui-doc-mode ;; toggle auto-showing type under cursor asa hover
"C-c F" #'lsp-format-buffer ;; run scalafmt on the entire buffer
"C-c f" #'lsp-format-region ;; run scalafmt on the selected region
"C-c C-f" #'lsp-find-references ;; find references symbol under cursor
"C-c i" #'lsp-execute-code-action ;; import missing type/class
"C-c r" #'lsp-rename ;; rename symbol
"C-c e" #'lsp-ui-flycheck-list ;; list all errors
@matfournier
matfournier / stupid.hs
Created December 26, 2019 06:08
stupid adt example
module Scratch where
data Shape = Circle { radius :: Int }
| Rectangle {length :: Int, width :: Int}
| Triangle {length :: Int, height :: Int}
deriving (Show, Eq)
-- how would you fromJSON shape assuming there
@matfournier
matfournier / example.hs
Last active December 26, 2019 04:03
conduit json parsing
avgForClient :: Purchase -> Double
avgForClient (Purchase _ products) =
let n = fromIntegral $ DT.length products
totals = sum $ price <$> products
in totals / n
-- outputs nullnullnullnull... unless the json is on a single line.
-- how to make this work for multi-line json?
main :: IO ()
@matfournier
matfournier / zioEnv.scala
Created December 15, 2019 01:21
zioEnv help
// a NoOpLogger of zio-logging for a logging effect
trait NoOpLogger extends Logging[String] {
def logging: Logging.Service[Any, String] = new Logging.Service[Any, String] {
override def trace(message: => String): ZIO[Any, Nothing, Unit] = ZIO.unit
override def debug(message: => String): ZIO[Any, Nothing, Unit] = ZIO.unit
override def info(message: => String): ZIO[Any, Nothing, Unit] = ZIO.unit
override def warning(message: => String): ZIO[Any, Nothing, Unit] = ZIO.unit
@matfournier
matfournier / example.scala
Last active December 3, 2019 22:34
RefinedCustomValidation
// the type I take in which isn't that useful
case class AuthorizeRequest(
code: Option[String],
token: Option[String],
secret: Option[String],
verifier: Option[String],
redirectUri: String,
clientId: String,
clientSecret: String
)
@matfournier
matfournier / Go.scala
Last active November 11, 2019 19:33
Monix Observable Help
import monix.eval.Task
import monix.execution.Scheduler.Implicits.global
import monix.reactive._
import scala.concurrent._
import scala.concurrent.duration._
// possibly useful
// https://github.com/monix/monix/issues/481
// https://stackoverflow.com/questions/45894205/getting-cassandra-query-results-asynchronously-using-scala-monix