Skip to content

Instantly share code, notes, and snippets.

View fernandomora's full-sized avatar

Fernando Mora fernandomora

View GitHub Profile
object Main extends App {
case class User(id: String, name: String)
val users = scala.collection.mutable.Map(
"1" -> User("1", "Fernando"),
"2" -> User("1", "Darren"),
)
object UserRepository {
def getUserById(id: String): Option[User] = {
@fernandomora
fernandomora / PrettyDuration.scala
Last active October 22, 2021 21:32
Helper to pretty print scala Duration
package com.intenthq.elasticsearchwriter.duration
import java.util.Locale
import java.util.concurrent.TimeUnit
import scala.concurrent.duration._
object PrettyDuration {
private val abbreviate = Map(
NANOSECONDS -> "ns",
@fernandomora
fernandomora / GroupableOps.scala
Created January 29, 2019 01:20
Scala groupMap from 2.13 for scala 2.12
import scala.collection.{immutable, mutable, GenTraversableOnce}
import scala.collection.generic.CanBuildFrom
object GroupableOps {
implicit class ToGroupable[A, Coll[X] <: GenTraversableOnce[X]](coll: Coll[A]) {
// https://github.com/scala/scala/blob/v2.13.0-M5/src/library/scala/collection/Iterable.scala#L578
def groupMap[K, B, To](key: A => K)(f: A => B)
(implicit bf: CanBuildFrom[Coll[A], B, To]): immutable.Map[K, To] = {
@fernandomora
fernandomora / genesis_public_key
Created February 21, 2018 15:47
genesis_public_key
04523be71ff5c62fe068b27465ea3d3967803755a4a2656d2aa7c55cd8b21636ecb2bd44aa42b5a071c99e1f744adbff04d8cba00ff2265bbb8bb89320b3e8d875;GMadorell
@fernandomora
fernandomora / keybase.md
Created April 25, 2017 09:04
keybase.md

Keybase proof

I hereby claim:

  • I am fernandomora on github.
  • I am fernandomora (https://keybase.io/fernandomora) on keybase.
  • I have a public key ASDHsShMVZBYpBVEZpGPHFEpP5FJ5ZVE7WPrIfx4Q8QHbwo

To claim this, I am signing this object:

@fernandomora
fernandomora / fswatch-rsync
Created September 12, 2016 22:43
Watch folder with fswatch and sync it with rsync
#!/usr/bin/env bash
# check color support
colors=$(tput colors)
if (($colors >= 8)); then
red='\033[0;31m'
nocolor='\033[00m'
else
red=
nocolor=
#!/usr/bin/env bash
# see https://help.github.com/articles/changing-author-info/
NAME=`basename ${BASH_SOURCE[0]}`
DESCRIPTION="Change any commits that previously had the old email address in its author or committer fields to use the correct name and email address."
# Define help function
function help(){
if [[ -z "$1" ]]; then echo "${NAME}: ${DESCRIPTION}"; else echo ${NAME}: $1; fi
@fernandomora
fernandomora / askpass
Last active September 12, 2016 22:38
Script to ask password interactively to avoid introducing it as an argument
#!/usr/bin/env bash
read -e -s -p 'Password: ' password
echo $password
import com.github.xiaodongw.swagger.finatra.{SwaggerSupport, SwaggerSupportBase}
import com.twitter.finagle.Filter
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finatra.http.Controller
import io.swagger.models.Swagger
import io.swagger.models.Operation
trait SwaggerFilterSupport extends SwaggerSupport { self: Controller =>
override protected implicit val swagger: Swagger
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(buildTrustAllSSLContext(), NoopHostnameVerifier.INSTANCE);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
HttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(new DefaultHttpClientConnectionOperator(socketFactoryRegistry, null, null), null, -1, TimeUnit.MILLISECONDS);
HttpClientBuilder clientBuilder = HttpClients.custom();
clientBuilder.setConnectionManager(cm);
class SniHttpClientConnectionOperator extends DefaultHttpClientConnectionOperator {
class SniSSLSocketFactory extends SSLConnectionSocketFactory {