Skip to content

Instantly share code, notes, and snippets.

View fernandomora's full-sized avatar

Fernando Mora fernandomora

View GitHub Profile
\setenv LESS '-iMSx4FXRe'
\pset pager always
\pset null ¤
\pset linestyle unicode
\pset border 2
-- Returns query time cost with each order
\timing
-- Returns more information on errors
@fernandomora
fernandomora / GenericSquare.scala
Created June 5, 2015 14:53
Generic function to square all the elements of a Iterable returning the original collection
def square[Element, IT[_] <: Iterable[Element], That](it: IT[Element])
(implicit bf: CanBuildFrom[IT[Element], Element, That],
num: Numeric[Element]): That = {
val b = bf.apply(it)
b.sizeHint(it)
it.foreach(elem => b += num.times(elem,elem) )
b.result()
}
@fernandomora
fernandomora / MonadSequence.scala
Last active October 14, 2015 17:52
Scala Monad sequence method for generic travesables using for-comprehensions and builder pattern
import scala.language.higherKinds
def sequence[A, M[X] <: TraversableOnce[X]](in: M[Monad[A]])(implicit cbf: CanBuildFrom[M[Monad[A]], A, M[A]]): Monad[M[A]] = {
val unit = Monad(cbf(in))
in.foldLeft(unit){
(mba, ma) => for (ba <- mba; a <- ma) yield ba += a
}.map(_.result())
}
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 {
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
@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
#!/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 / 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=
@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 / genesis_public_key
Created February 21, 2018 15:47
genesis_public_key
04523be71ff5c62fe068b27465ea3d3967803755a4a2656d2aa7c55cd8b21636ecb2bd44aa42b5a071c99e1f744adbff04d8cba00ff2265bbb8bb89320b3e8d875;GMadorell