Skip to content

Instantly share code, notes, and snippets.

View pvillega's full-sized avatar
😶‍🌫️
Too much!

Pere Villega pvillega

😶‍🌫️
Too much!
View GitHub Profile
### Keybase proof
I hereby claim:
* I am pvillega on github.
* I am pvillega (https://keybase.io/pvillega) on keybase.
* I have a public key whose fingerprint is 4003 AFBF D975 6FE9 95ED 3813 4D71 E911 8574 2DBC
To claim this, I am signing this object:
@pvillega
pvillega / gist:9271089849176fdfff0a
Created January 28, 2015 08:32
BAPI request sign steps
public void signRequest(Request request) {
if (apiKey != null) {
try {
request.queryParameter(API_KEY_NAME, bapiKey);
request.queryParameter(TIMESTAMP_NAME, String.valueOf(System.currentTimeMillis()));
request.queryParameter(SIGNATURE_NAME, sign(getSignablePart(request), apiKey.getPrivateKey()));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
@pvillega
pvillega / gist:aa21f7ef609fd210627a
Last active August 29, 2015 14:14
Example of 'packages' request and payload
Given the following request to a QA bapi instance, signed as specified in the document we sent:
http://bapi.qa8.gumtree.com/api/accounts/101981/packages?timestamp=1422961797794&signature=3d311860aa1bf1bd912ff0880102999f9c46a3670e8fb7ea9f71f112cb72e1a1&apiKey=c7deb878d73c3d3468a53a16f2c4232d
Your response will have the following headers:
Content-Type → application/json;charset=UTF-8
Date → Tue, 03 Feb 2015 11:10:44 GMT
Server → GumBackend
Transfer-Encoding → chunked
[
{name: 'Afghanistan', code: 'AF'},
{name: 'Åland Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
{name: 'Algeria', code: 'DZ'},
{name: 'American Samoa', code: 'AS'},
{name: 'AndorrA', code: 'AD'},
{name: 'Angola', code: 'AO'},
{name: 'Anguilla', code: 'AI'},
{name: 'Antarctica', code: 'AQ'},
@pvillega
pvillega / sample.scala
Created June 5, 2016 20:58
Can we merge the interpreters?
// simplified code to give the idea. Starting with 2 DSL, Trades and Http
object Trades {
sealed trait DSL[A] { def url: String }
final case class HeartBeat() extends DSL[TradeResult[StatusOk]]
type TradesPRG[A] = (DSL :|: FXNil)#Cop[A]
}
object Http {
sealed trait DSL[A]
// Sample of code
// Trades Api
case object IsApiUp extends DSL[Xor[ErrorMessage, Ok]]
final case class Buy(venue: Sring, account: String, order: Order) extends DSL[Xor[ErrorMessage, NewOrderResponse]]
final case class VenueStocks(venue: String) extends DSL[Xor[ErrorMessage, List[Stock]]]
// Program
type API = LogApi.PRG :||: TradeApi.PRG
@pvillega
pvillega / freekOnionReturn.scala
Last active August 16, 2016 19:00
Can we return just Xor[String, Boolean] and skip the List?
// If I have a very simple program
def example2(venue: String, account: String) = for {
_ <- info("blah blah").freeko[API, O] // Returns Unit
b <- buy(venue, account, Order("BAD", -1, -1)).freeko[API, O] // Returns Result[OrderStatus]
} yield b
// with API definition and Onion
type Result[A] = Xor[String, A]
type API = LogApi.PRG :||: TradeApi.PRG
val API = Program[API]
@pvillega
pvillega / MainServer.scala
Created December 11, 2016 19:35
Metrics not working :(
object MainServer extends TwitterServer {
override def failfastOnFlagsNotParsed: Boolean = true
// some flags received via config
val port: Flag[Int] = flag("port", 8081, "TCP port for HTTP server")
// logging formatter
override def defaultFormatter = new Formatter(
timezone = Some("UTC"),
prefix = "<yyyy-MM-dd HH:mm:ss.SSS> [%.3s] %s: "
@pvillega
pvillega / doobie-refined-meta-composite.scala
Created February 22, 2017 19:36
Allow Refined types on case classes used by Doobie
// Credit to Kevin Horlick @beefyhalo fir the Meta implementation
// See https://gitter.im/tpolecat/doobie/archives/2015/12/22
// It wasn't straightforward to find the answer, my Google-foo is weak, so I hope
// this helps people looking for this answer
// allows generation of doobie Meta objects from Refined types
implicit def refinedMeta[T: Meta, P, F[_, _]](implicit tt: TypeTag[F[T, P]],
ct: ClassTag[F[T, P]],
validate: Validate[T, P],
refType: RefType[F]): Meta[F[T, P]] =
@pvillega
pvillega / NaughtyStringsList.scala
Created May 29, 2017 12:02
List of Strings you may want to use for testing in input fields, as they can cause unexpected behaviour.
// List of Strings you may want to use for testing in input fields, as they can cause unexpected behaviour. Input fields
// should either return validation errors or sanitize them.
// Using mostly Strings due to the way JVM manages Chars with Unicode.
// Based on https://github.com/minimaxir/big-list-of-naughty-strings - version 29th May 2017 - update as required
import org.scalacheck.Gen
trait NaughtyStringsList {
val naughtyReservedStrings: Gen[String] = Gen.oneOf(