Skip to content

Instantly share code, notes, and snippets.

Avatar

Amir Karimi amirkarimi

View GitHub Profile
@amirkarimi
amirkarimi / my_useful_regexes.md
Last active Jun 17, 2020
My Useful Regular Expressions
View my_useful_regexes.md

My Useful Regular Expressions

The first lines are the regex to find and the last line are the replace expressions.

YAML

Convert single quoted values to double in YAML

:(\s?)'(.*)'
View blog_practical_cats_06.scala
def getCountryByUserId(id: Int): Future[Either[String, Country]] = {
val result = for {
user <- EitherT(getUser(id))
city <- EitherT(getCity(user))
country <- EitherT(getCountry(city))
} yield {
country
}
result.value
}
View blog_practical_cats_05.scala
def getUser(id: Int): Future[Either[String, User]] = ???
def getCity(user: User): Future[Either[String, City]] = ???
def getCountry(city: City): Future[Either[String, Country]] = ???
def getCountryByUserId(id: Int): Future[Either[String, Country]] = {
getUser(id) flatMap {
case Left(err) => Future.successful(Left(err))
case Right(user) =>
getCity(user) flatMap {
case Left(err) => Future.successful(Left(err))
View blog_practical_cats_04.scala
def getCountryByUserId(id: Int): Future[Option[Country]] = {
val result = for {
user <- OptionT(getUser(id))
city <- OptionT(getCity(user))
country <- OptionT(getCountry(city))
} yield {
country
}
result.value
}
View blog_practical_cats_03.scala
def getUser(id: Int): Future[Option[User]] = ???
def getCity(user: User): Future[Option[City]] = ???
def getCountry(city: City): Future[Option[Country]] = ???
def getCountryByUserId(id: Int): Future[Option[Country]] = {
getUser(id) flatMap {
case None => Future.successful(None)
case Some(user) =>
getCity(user) flatMap {
case None => Future.successful(None)
View blog_practical_cats_02.scala
def getUser(id: Int): Future[Option[User]] = ???
getUser(10).map {
case None => println(“User not found”)
case Some(user) => println(s”User: $user”)
}
@amirkarimi
amirkarimi / blog_practical_cats_01.scala
Last active Jan 3, 2018
Don’t listen to them, learn Cats this way
View blog_practical_cats_01.scala
def getUser(id: Int): Option[User] = ???
getUser(10) match {
case None => println(“User not found”)
case Some(user) => println(s”User: $user”)
}
@amirkarimi
amirkarimi / sort-import-group.el
Last active Aug 7, 2017
My Emacs Lisp Scripts
View sort-import-group.el
(defun sort-import-group ()
"This function basically sorts a comma separated list of strings but it's been
written to sort grouped imports in Scala.
Example:
`import org.temp.{ B, C, A }`
By selecting the grouped imported items (`B, C, A`) from the above code sample and run (M-x) `sort-group`
you'll get the following result:
`import org.temp.{ A, B, C }`"
(interactive)
(let* ((bounds (cons (region-beginning) (region-end)))
View linux_init.el
;; global variables
(setq
inhibit-startup-screen t
create-lockfiles nil
make-backup-files nil
column-number-mode t
scroll-error-top-bottom t
show-paren-delay 0.5
use-package-always-ensure t
sentence-end-double-space nil
@amirkarimi
amirkarimi / 01.scala
Last active May 17, 2017
01-apply-settings-using-sbt-triggered-plugin
View 01.scala
lazy val commonSettings = Seq(
organization := "com.example",
version := "0.1.0-SNAPSHOT"
)
lazy val core = (project in file("core"))
.settings(
commonSettings,
// other settings
)
You can’t perform that action at this time.