Skip to content

Instantly share code, notes, and snippets.

View BalmungSan's full-sized avatar
👨‍🏫
Learning & Teaching

Luis Miguel Mejía Suárez BalmungSan

👨‍🏫
Learning & Teaching
View GitHub Profile
@eugene-sy
eugene-sy / build.gradle
Created December 20, 2018 13:29
Gradle - Scapegoat integration
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Scala library project to get you started.
* For more details take a look at the Scala plugin chapter in the Gradle
* user guide available at https://docs.gradle.org/5.0/userguide/scala_plugin.html
*/
plugins {
// Apply the scala plugin to add support for Scala
@gregberns
gregberns / the-algebra-of-algebraic-data-types.md
Created December 13, 2018 05:57
The Algebra of Algebraic Data Types, Part 1, by Chris Taylor
@BalmungSan
BalmungSan / StreamAsJsonArrayEncoder.scala
Created August 19, 2018 14:23
Http4s EntityEncoder for returning Streams as JSONArrays using Circe.
import cats.Applicative
import cats.effect.IO
import fs2.Stream
import io.circe.Encoder
import io.circe.generic.semiauto.deriveEncoder
import io.circe.syntax.EncoderOps
import org.http4s.{EntityEncoder, MediaType}
import org.http4s.dsl.io._
import org.http4s.headers.`Content-Type`
@BalmungSan
BalmungSan / UTCZonedDateTimeMongoCodec.scala
Last active February 19, 2022 08:00
Custom MongoDB codec for reading/writing ZonedDateTime instances in UTC
import cats.effect.IO
import io.circe.Encoder
import io.circe.generic.semiauto.deriveEncoder
import io.circe.java8.time.encodeZonedDateTimeDefault
import io.circe.syntax.EncoderOps
import org.bson.{BsonReader, BsonType, BsonWriter}
import org.bson.codecs.{DecoderContext, Codec, EncoderContext}
import org.bson.codecs.configuration.{CodecConfigurationException, CodecRegistries}
import org.mongodb.scala.MongoClient
import org.mongodb.scala.bson.codecs.{DEFAULT_CODEC_REGISTRY, Macros}
@smarter
smarter / fmap.scala
Last active November 18, 2019 08:55
Should work with 0.20.0-RC1
// Compiles with https://github.com/lampepfl/dotty/pull/4672
// ./bin/dotc -classpath "$(coursier fetch -p org.typelevel:cats-core_2.13:2.0.0)" out/fmap.scala
import cats._
import cats.implicits._
object Test {
val fmap: [A, B] -> (A => B) => [F[_]] -> F[A] => (given Functor[F]) => F[B] = [A, B] -> (f: A => B) => ([F[_]] -> (fa: F[A]) => (given ev: Functor[F]) => fa.map(f))
val addOne = fmap((x: Int) => x + 1)
@Daenyth
Daenyth / MonadAndFs2Ops.md
Last active June 25, 2024 13:04
Cheat sheet for common cats monad and fs2 operation shapes
Operation Input Result Notes
map F[A] , A => B F[B] Functor
apply F[A] , F[A => B] F[B] Applicative
(fa, fb, ...).mapN (F[A], F[B], ...) , (A, B, ...) => C F[C] Applicative
(fa, fb, ...).tupled (F[A], F[B], ...) F[(A, B, ...)] Applicative
flatMap F[A] , A => F[B] F[B] Monad
traverse F[A] , A => G[B] G[F[A]] Traversable; fa.traverse(f) == fa.map(f).sequence; "foreach with effects"
sequence F[G[A]] G[F[A]] Same as fga.traverse(identity)
attempt F[A] F[Either[E, A]] Given ApplicativeError[F, E]
@Geoyi
Geoyi / install virtualenv ubuntu 16.04.md
Created September 16, 2017 12:19 — forked from frfahim/install virtualenv ubuntu 16.04.md
How to install virtual environment on ubuntu 16.04

How to install virtualenv:

Install pip first

sudo apt-get install python3-pip

Then install virtualenv using pip3

sudo pip3 install virtualenv 

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@kekru
kekru / add CA cert on CentOS Debian Ubuntu.md
Last active December 30, 2024 09:31
Add CA cert to local trust store on CentOS, Debian or Ubuntu
  • Open a webpage that uses the CA with Firefox
  • Click the lock-icon in the addressbar -> show information -> show certificate
  • the certificate viewer will open
  • click details and choose the certificate of the certificate-chain, you want to import to CentOS
  • click "Export..." and save it as .crt file
  • Copy the .crt file to /etc/pki/ca-trust/source/anchors on your CentOS machine
  • run update-ca-trust extract
  • test it with wget https://thewebsite.org
@nadavmatalon
nadavmatalon / mapf.ino
Created October 12, 2016 15:13
ARDUINO: MAP FLOAT FUNCTION
double mapf(double val, double in_min, double in_max, double out_min, double out_max) {
return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}