Skip to content

Instantly share code, notes, and snippets.

package zio
object PathDependentTypes {
val zio1: ZIO[Any, Nothing, Int] = ZIO.succeed(1)
val zio2: ZIO[Any, Nothing, Int] = ZIO.succeed(2)
val zio3: ZIO[Any, Nothing, Int] = ZIO.succeed(3)
val zio4 = zio1 <*> zio2 <*> zio3 <*> zio1 <*> zio2
@diesalbla
diesalbla / recscheme.scala
Last active November 11, 2019 16:06
A lightweight Introduction to Recursion Schemes in Scala
/**
* Code Snippets from the Blog Post "Basic Recursion Schemes in Scala",
* https://www.47deg.com/blog/basic-recursion-schemes-in-scala/
*
* Written here to accompany the article. This file should compile directly if inserted into ammonte.
*/
object IListBase {
sealed trait IList
case object INil extends IList
case class ICons(head: Int, tail: IList) extends IList
@Daenyth
Daenyth / 1-MapTraverse.md
Last active June 25, 2024 13:05
Scala (cats) map/traverse parallels

Parallels between map and similar functions

map          :: F[A] => (A =>     B)   => F[B]
flatMap      :: F[A] => (A =>   F[B])  => F[B]
traverse     :: G[A] => (A =>   F[B])  => F[G[B]]
flatTraverse :: G[A] => (A => F[G[B]]) => F[G[B]]
traverse_    :: F[A] => (A =>   F[B])  => F[Unit]
@ElisaBaum
ElisaBaum / Consumer.scala
Last active August 27, 2020 08:06
Kafka Producer/Consumer Example in Scala
import java.util.Properties
import scala.collection.JavaConverters._
import org.apache.kafka.clients.consumer.{ConsumerConfig, ConsumerRecords, KafkaConsumer}
import org.apache.kafka.common.serialization.StringDeserializer
class Consumer(brokers: String, topic: String, groupId: String) {
val consumer = new KafkaConsumer[String, String](configuration)
consumer.subscribe(List(topic).asJava)
@lschuetze
lschuetze / build-with-profile.sbt
Last active November 30, 2018 09:26
Profiles with SBT (Scala Build Tool)
lazy val Profile = config("profile") extend(Runtime)
lazy val commonSettings = Seq(
organization := "organization",
version := "0.0.1",
scalaVersion := "2.12.0",
scalacOptions ++= Seq(
"-encoding", "utf8",
"-deprecation",
"-feature",
@ipbastola
ipbastola / jq to filter by value.md
Last active June 21, 2024 14:29
JQ to filter JSON by value

JQ to filter JSON by value

Syntax: cat <filename> | jq -c '.[] | select( .<key> | contains("<value>"))'

Example: To get json record having _id equal 611

cat my.json | jq -c '.[] | select( ._id | contains(611))'

Remember: if JSON value has no double quotes (eg. for numeric) to do not supply in filter i.e. in contains(611)

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@ericclemmons
ericclemmons / example.md
Last active April 24, 2024 18:09
HTML5 <details> in GitHub

Using <details> in GitHub

Suppose you're opening an issue and there's a lot noisey logs that may be useful.

Rather than wrecking readability, wrap it in a <details> tag!

<details>
 Summary Goes Here
@androidfred
androidfred / haskell_stack_and_intellij_idea_ide_setup_tutorial_how_to_get_started.md
Last active May 6, 2024 19:13
Haskell, Stack and Intellij IDEA IDE setup tutorial how to get started

Haskell, Stack and Intellij IDEA IDE setup tutorial how to get started

Upon completion you will have a sane, productive Haskell environment adhering to best practices.

Basics

  • Haskell is a programming language.
  • Stack is tool for Haskell projects. (similar tools for other languages include Maven, Gradle, npm, RubyGems etc)
  • Intellij IDEA IDE is a popular IDE.

Install required libraries

sudo apt-get install libtinfo-dev libghc-zlib-dev libghc-zlib-bindings-dev

# coding: utf8
from __future__ import unicode_literals
maketrans = lambda A, B: dict((ord(a), b) for a, b in zip(A, B))
buckwalter_transliteration = maketrans('\'>&<}AbptvjHxd*rzs$SDTZEg_fqklmnhwYyFNKaui~o^#`{:@"[;,.!-+%]', 'ءأؤإئابةتثجحخدذرزسشصضطظعغـفقكلمنهوىيًٌٍَُِّْٓٔٱۣۜ۟۠ۢۥۦ۪ۭۨ۫۬')
# usage
print 'r~aHoma`ni'.translate(buckwalter_transliteration)