Skip to content

Instantly share code, notes, and snippets.

View frgomes's full-sized avatar

Richard Gomes frgomes

View GitHub Profile
@frgomes
frgomes / finch-no-exceptions.md
Created July 19, 2018 16:38 — forked from vkostyukov/finch-no-exceptions.md
Finch: A Life Without Exceptions

Finch: A Life Without Exceptions

Historically, Finch's error handling machinery was built on a very simple yet silly idea that an Endpoint may return a failed Future (i.e., Future.exception). While that doesn't really promote a purely functional approach to error handling (i.e., treat errors as values), it enables quite a few handy setups, including:

  • embedding 3rd-party Finagle clients (that may fail) within endpoints w/o extra boilerplate
  • simple/minimal required endpoints (i.e., body, param, etc) that return A, not Try[A] nor Either[Error, A]

However this part of Finch's design was heavily influenced by Finagle itself (w.r.t. embedding all of its failures in Future.exception), nothing stops us from revisiting this trade-off and possibly discussing paths forward more idiomatic error handling.

Implicit Errors vs. Explicit Errors

@frgomes
frgomes / f10.md
Created July 19, 2018 16:36 — forked from vkostyukov/f10.md
Finch 1.0

The [Future Finch][1] writeup defines a vector in which Finch 1.0 should be developed. The goal for 1.0 is to build very clean, simple, well-tested and composable core based on purely functional constructs and immutable data. The core will provide a solid ground for the micro-frameworks, which should land in Finch 2.0.

This document consists of two parts. The first part presents a high-level picture of Finch 1.0. The second part describes required steps we, Finch contributors and maintainers, have to make in order to bring the library to its first stable version.

One Abstraction to Rule Them All

Looking at the current API, one can find a slight correlation between Routers and RequestReaders. They both take a request and produces a value of type A from it. They both functions: HttpRequest => A. Keeping that in mind, [the idea of composing them ][2] into a single thing (perhaps Router) has found its supporters. The next reasonable step would be to completely merge those abstractions into a sing

@frgomes
frgomes / bash_find_printers.sh
Created June 14, 2018 21:13
Bash - Find printers
#!/bin/bash
sudo apt install avahi-ui-utils kde-zeroconf avahi-utils cups-client -y
sudo lpinfo --include-schemes dnssd -v
# More info: https://www.cups.org/doc/network.html
@frgomes
frgomes / debian_headset.sh
Last active May 26, 2018 18:14
Debian - Pulseaudio, bluetooth, equalizer, headset, headphone, a2sp/hsp/hfp
#!/bin/bash
sudo apt install -y pavucontrol pulseaudio-module-bluetooth pulseaudio-equalizer
sudo service bluetooth restart
pacmd load-module module-bluetooth-discover
pacmd load-module module-dbus-protocol
@frgomes
frgomes / firefox_via_ssh_tunnel.sh
Last active September 13, 2019 13:30
Bash - Firefox via SSH tunnel
# create a SSH tunnel between 127.0.0.1:18080 <--> internal.example.com:8080
$ ssh -L 127.0.0.1:18080:internal.example.com:8080 [email protected]
# open Firefox on the local computer, which will send and receive data via the SSH tunnel
$ firefox http://127.0.0.1:18080
@frgomes
frgomes / FoldLeftWithMapBreakOut.scala
Created April 24, 2018 13:33
Scala - FoldLeft resulting a mutable Map, employing collection.breakOut
def pairsToMap(pairs: Seq[(Key, DenseVector[Long])]): mutable.Map[Key, DenseVector[Long]] =
(Map.empty[Key, DenseVector[Long]] /: pairs) {
case (acc, item) =>
val k: Key = item._1
val v: DenseVector[Long] = item._2
acc + (k -> v) }
.map(identity)(collection.breakOut)
import numpy as np
def secs(ms): return ms / 1000
header = ['recs','elapsed','cleanse','kvpairs','wdict','wschema','wtable','rdict','rschema','rtable','wcsv']
data = np.loadtxt('metrics.csv',
delimiter = ',',
dtype = {'names' : ( header ),
'formats': ( 'i4','i4','i4','i4','i4','i4','i4','i4','i4','i4','i4' )})
@frgomes
frgomes / uTestActions.scala
Last active April 17, 2018 22:23
Scala - utest: pending and ignore
import com.typesafe.scalalogging.StrictLogging
trait uTestActions extends StrictLogging {
def ignored(action: ⇒ Unit): Unit = ignored
def pending(action: ⇒ Unit): Unit = {
try {
action
} catch {
case t: Throwable => pending(t)
}
}
// This may help circumvent bug 31407
// union FloatBits { float: f64, bits: u64 }
pub const MYCONST : f64 = FloatBits { bits: 1 << 63 }.float;
@frgomes
frgomes / logback.xml
Created March 28, 2018 11:17
Scala - LogBack: setting root level
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %-5level [%thread] %logger{0}: %msg%n</pattern>
<outputPatternAsHeader>false</outputPatternAsHeader>
</encoder>
</appender>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${HOME}/.myapp/logs/myapp.log</file>