Skip to content

Instantly share code, notes, and snippets.

View evbruno's full-sized avatar

Eduardo V. Bruno evbruno

View GitHub Profile
// participation.cpp
#include<iostream>
using std::cout;
using std::endl;
void nope() {}
void participation() { return nope(); }
int main() {
participation();
@evbruno
evbruno / EnableCORSDirectives.scala
Last active August 5, 2016 13:24
Akka-http (spray) directive to allow CORS (Cross-Origin Resource Sharing)
import akka.http.scaladsl.model.HttpMethods._
import akka.http.scaladsl.model.headers.{`Access-Control-Allow-Credentials`, `Access-Control-Allow-Headers`, `Access-Control-Allow-Methods`, `Access-Control-Allow-Origin`}
import akka.http.scaladsl.server.directives.RespondWithDirectives
trait EnableCORSDirectives extends RespondWithDirectives {
private val allowedCorsVerbs = List(
CONNECT, DELETE, GET, HEAD, OPTIONS,
PATCH, POST, PUT, TRACE
)
@evbruno
evbruno / HttpApp.scala
Created February 25, 2016 18:34
Posting a JSON content with http4s / scalaz
// build.sbt
// "org.http4s" %% "http4s-client" % "0.12.3",
// "org.http4s" %% "http4s-blaze-client" % "0.12.3",
// "org.http4s" %% "http4s-dsl" % "0.12.3",
import org.http4s.MediaType._
import org.http4s.client._
import org.http4s.client.blaze.{defaultClient => client}
import org.http4s.dsl._
import org.http4s.headers._
@evbruno
evbruno / Dockerfile
Created August 4, 2016 20:16
Dockerfile derived from official PostgreSQL with rvm/ruby/rails
### Container based on official postgres v9.5.3, with:
# * rvm
# * ruby 2.2.3
# * rails 4.2.3
###
FROM postgres:9.5.3
RUN apt-get update && apt-get install -y curl git libpq-dev
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
@evbruno
evbruno / flight-delay-spark.scala
Created November 22, 2016 16:04
Flight Delay computing with Spark
// ref: https://github.com/evbruno/flight_delay_akka_streams
// ref: https://github.com/evbruno/flight_delay_java8
// 0 : load
val flightText = sc.textFile("/tmp/2008.csv").cache
case class FlightEvent(
year: String,
month: String,
@evbruno
evbruno / MyPlaygroundCaixa.swift
Created June 9, 2017 14:59
Conta simples para cálculo do financiamento SAC (parcelas decrescentes)
//: Playground - noun: a place where people can play
import UIKit
class CalculadoraFinanciamento : CustomDebugStringConvertible {
let valorFinanciado, amortizacao, jurosMensal: Double
init(_ valorImovel: Double, valorEntrada: Double, parcelas: Int, jurosMensal: Double) {
self.valorFinanciado = valorImovel - valorEntrada
@evbruno
evbruno / SupervisorSample.scala
Last active March 28, 2018 17:27
Akka Supervisor Sample
import akka.actor.SupervisorStrategy._
import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, OneForOneStrategy, Props}
import akka.stream.ActorMaterializer
import scala.collection.mutable.{Map => MMap}
import scala.concurrent.duration._
import scala.io.StdIn
object SupervisorSample extends App {
@evbruno
evbruno / SSHActor.scala
Created March 30, 2018 13:41
SSH Client with akka's Actor
// build.sbt: libraryDependencies += "com.jcraft" % "jsch" % "0.1.54"
// docker image with sshd: https://docs.docker.com/engine/examples/running_ssh_service/
package etc.bruno.ssh
import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, Props}
import akka.pattern.{ask, pipe}
import akka.util.Timeout
import com.jcraft.jsch._
import etc.bruno.ssh.SSHActor._
```
.------------------+-----------------------------------------------------------------+-----------+--------------------------------------------------+--------+--------------------+----------+----------+----------------+---------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+------------------+----------------------+---------+------------.
|
@evbruno
evbruno / CalculadoraFinanciamentoSAC.scala
Last active July 6, 2018 16:59
CalculadoraFinanciamentoSAC
case class DadosFinanciamento(valorFinanciado: Double,
amortizacao: Double,
parcelas: Int,
jurosMensal: Double)
case class ParcelaCalculada(numDaParcela: Int,
valor: Double,
jurosSobreSaldo: Double,
saldoDevedor: Double) {