Skip to content

Instantly share code, notes, and snippets.

@amirkarimi
amirkarimi / karabiner-elements-linux-rules.json
Last active December 10, 2022 04:50
Karabiner Elements Linux shortcuts for Mac
[
{
"description": "Control+Click to Command+Click",
"manipulators": [
{
"from": {
"modifiers": {
"mandatory": [
"control"
],
@amirkarimi
amirkarimi / my_useful_regexes.md
Last active June 17, 2020 16:24
My Useful Regular Expressions

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?)'(.*)'
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
}
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))
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
}
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)
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 January 3, 2018 21:47
Don’t listen to them, learn Cats this way
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 August 7, 2017 09:28
My Emacs Lisp Scripts
(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)))
@amirkarimi
amirkarimi / linux_init.el
Last active September 9, 2017 20:45
My Emacs Config
;; 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