Lisbon Travel Tips (里斯本 旅游攻略)

Lisbon is a beautiful city and suitable for a 3-4 days travel. After spending days here and I got some lessons learned during the travel. I want to write them down to help others to have a better stay.

  • Lisbon Airport is a mess, you should plan 2 hours ahead for the flights.
  • Uber and Bolt work in Lisbon, better to use them instead of Taxi. If you choose Taxi, ask the driver to use the taximeter. And prepare the cash.
  • At the airport, you could buy the Lisbon Card. With it, you could take free public transport like the tramway and access to many museums and historical sites.
  • Always buy the tickets for top attractions (Jeronimo’s monastery for example) online to avoid long queues.
  • Most of the museums are closed on Monday!!!
  • At the famous Pastéis de Belém near Jeronimo’s monastery, you could see a very long queue, but it is only for taking away. You could enter directly into the boutique to eat on the table. It is more comfortable and easy.
  • If you want to see Fado Music, you could go to “O Faia” restaurant. The music and food are top but they have minimum price each person is 50 euros and the show begins only at 21H30 PM.
  • Be careful to eat in the restaurants in the Alfama area, they could charge you service fees without telling you before.
  • You could download the “lonely planet app” to help you organize your visits.
  • In the end, Lisbon is a tourist city and there are really many tourists and also thieves. And don’t forget to bring comfortable Sportif shoes!

Probabilistic Data Structures

Context: When we are dealing with a very large set of data or a data streaming, we could not put them all in the memory.

1.Bloom filter: Used to query if the item exists (Membership query). A Bloom filter is a bit array of m bits initialized to 0. To add an element, feed it to k hash functions to get k array position and set the bits at these positions to 1. To query an element, feed it to k hash functions to obtain k array positions. If any of the bits at these positions is 0, then the element is definitely not in the set. If the bits are all 1, then the element might be in the set.

2. HyperLogLog: used for estimating the number of distinct elements (Cardinality). HyperLogLog counter can count one billion distinct items with an accuracy of 2% using only 1.5 KB of memory. It is based on the bit pattern observation that for a stream of randomly distributed numbers if there is a number x with the maximum of leading 0 bits k, the cardinality of the stream is very likely equal to 2^k.

3. Count-Min Sketch: used for querying single item count(Frequency).The basic data structure is a two-dimensional d , w array of counters with d pairwise independent hash functions h1 … hd of range w.

Link from


  • Stateless:  RESTFul API is stateless. A stateless protocol does not require the server to retain session information or status about each communicating partner for the duration of multiple requests.

UDP, HTTP, and IP are stateless protocols. TCP is stateful.

  • HEAD, GET, OPTIONS and TRACE are SAFE methods,which means they are intended only for information retrieval and should not change the state of the server. In other words, they should not have side effects.


  • Methods PUT and DELETE are defined to be idempotent, meaning that multiple identical requests should have the same effect as a single request. Methods GET, HEAD, OPTIONS, and TRACE, being prescribed as safe, should also be idempotent.


Some thoughts on Startup

It has been a year and a half that I am working in a Fintech Startup in Paris France. There are more and more personal thoughts which might be different and realistic.

  • B2C is hard. Nowadays, especially here in France, many well-funded startups are B2B.  Public users always like the free and easy to use products. Many B2C products gain from advertising (Facebook ) or their content (Spotify).


  • Scale and growth is the key. The investor gives you money only because your product can achieve extreme growth that means your product could be easily implemented in other countries or markets.


  • Business Model is vital.  Business Model -> revenue or higher invest funds-> growth-> good salary (perks)->top talents-> top team-> top product-> revenue or higher invest funds.  Business Model is every beginning of this cycle. Some startups might have greet users database but no business model and eventually be acquired by other Giants. (Like Zenly)


  • Bussiness drive IT.  IT supports business operation and growth. And business growth brings the Technique challenges (like Alibaba). Without business scenario, all the cutting-edge tech staff is nonsense.


  • Top Talent makes it different. Always people matters, people make it happen. Top talent drives the crazy growth of the startup.

AWS S3 SDK Java Feedback

  • Verify if Bucket already exists

call the doesBucketExist method

  • Create Subdirectory (folder): using key

PutObjectRequest request = new PutObjectRequest(bucketName, "folder/", new File(fileName));

  • Remove all the files under folder:

    using key like : folder/

  • Using Presigned Url to share object (public url)

Often we need upload a file (image) to S3 and get a tempory public URL of this object. (Be careful, you should always set private-access to this object)

We could use Presigned-url with an expiration period.

Code Example

Integration Okta with your web application

1. Introduction Okta

Okta is an amazing identity management SasS products. It provides single sign-on solution, serves as a Security Gateway and it can protect all the internal employee daily used applications.

It also provides Okta API, so you can integrate their solution into your application. For example, you can use okta authentication and authorization API to control login.

2. Create a Okta Web Application

You start by sign up in Okta Developer .  And then create a Web Application :

Specify Login redirect URIs

3. Integration Front End : okta_sign-in_widget

You could use Okta Sign-In Widget  as your login page.

var signIn = new OktaSignIn({baseUrl: ''});
    el: '#widget-container'
  }, function success(res) {
    if (res.status === 'SUCCESS') {
      console.log('Do something with this sessionToken', res.session.token);
    } else {
    // The user can be in another authentication state that requires further action.
    // For more information about these states, see:
4. Integration Back End:  Implement the Authorization Code Flow

At a high-level, this flow has the following steps (copy from doc Okta):

  • Your application directs the browser to the Okta Sign-In page, where the user authenticates.
  • The browser receives an authorization code from your Okta authorization server.
  • The authorization code is passed to your application.
  • Your application sends this code to Okta, and Okta returns access and ID tokens, and optionally a refresh token.
  • Your application can now use these tokens to call the resource server (for example an API) on behalf of the user.

As mentioned in the above login widget javascript, you could get a res.session.token, you send this session token to backend controller.

Backend controller use this session token call /authorize endpoint to get a code (you might get a 302 response and in the response header you could find a location with a URI contains code param)

After that, using code to call /token endpoint to get the access and ID tokens.

Akka Actor – Scala

1. Akka Actor:

Actor Model: One of the technologies used to deal with deal with concurrent computation. (The other two are: Reactor and Event Driven).

2. Create Actor:

Actors are implemented by extending the Actor base trait and implementing the receivemethod.
Props is a configuration class to specify options for the creation of actors.

class SenderActor(message: String, receiverActor: ActorRef) extends Actor {

  var receivedMessage = ""

  def receive = {
    case WhoToSend(who) =>
      receivedMessage = s"$message, $who"
    case Message =>
      receiverActor !Print(receivedMessage)
3. Actor communication(in scala):
  • ! means “fire-and-forget”, e.g. send a message asynchronously and return immediately. Also known as tell.
  • ? sends a message asynchronously and returns a Future representing a possible reply. Also known as ask.

object MainApp extends App {
  val system : ActorSystem = ActorSystem("MainApp")

  val receiverActor: ActorRef = system.actorOf(Receiver.props, "Receiver")

  val sender1: ActorRef = system.actorOf(Sender.props("Bob", receiverActor),"Sender1")

  sender1 ! WhoToSend("Tom")
  sender1 ! Message

Github Source Code

Build Reactive Restful API Using Spring 5 (WebFlux), Springboot

1. Spring 5 WebFlux

Spring 5 includes a new reactive module called WebFlux. It builds on the reactive streams. (Key Spring Doc)

WebFlux support two programming models: one is traditional based@controller, the other is functional Java 8 lambda style routing and handling.  Here we will take a look at the second one.

In general, the second WebFlux model takes incoming http request, handed by the HandlerFunction , then http request body transforms to as Flux or Mono;

Flux and Mono come from the reactor (doc). A Flux object represents a reactive sequence of 0..N items, while a Monoobject represents a single-value-or-empty (0..1) result.

2. Code example

2.1 Create a handler:

public class UserHandler {

    public Mono<serverresponse> getUser(ServerRequest request){
                String uuid = request.pathVariable("uuid");
                return ServerResponse
                        .body(BodyInserters.fromObject(new UserJson(uuid, "bob")));
            }catch (IllegalArgumentException i){
                return ServerResponse.badRequest()

2.2 Create a route:

public class UserRouter {

    public RouterFunction<serverresponse> route(UserHandler userHandler){
        return RouterFunctions.route(RequestPredicates.GET("/users/{uuid}").

Source Code example Github


Building Restful API using Springboot

1.Create Spring-boot project

IntelliJ IDEA CE doesn’t support “spring initializr” plugin, so we should initial a SpringBoot project using

Download and unzip project, import it into IntelliJ.

2. Coding
  • Using  @RestController annotation which equals :  @controller + @ResponseBody
  •  Springboot main class should be in the same package with controllers and it should be in the root.

  • Code Controller:

public class UserController {

    @RequestMapping(value = "/users/{uuid}", method = RequestMethod.GET)
    public ResponseEntity getUser(@PathVariable("uuid") String uuid) {
        UserJson userJson = new UserJson(uuid, "bob");
        return new ResponseEntity<>(userJson, HttpStatus.OK);
  • Code Entity:

public class UserJson {

    @JsonProperty(value = "uuid")
    private String uuid;

    @JsonProperty(value = "name")
    private String name;

    public UserJson(String uuid, String name) {
        this.uuid = uuid; = name;
  • Run project

Configration Context and Port (Modifiy

./gradlew build bootRun

Source Code Github

Learning Flask Python – 0

1. Install python3 (Mac)

brew install python3
2. Install PIP (Python Package Index)

curl &gt;
sudo python
3. Install virtualenv (a tool to create isolated Python environments)

sudo pip install virtualenv
4.Create a project

$ mkdir myproject
$ cd myproject
$ virtualenv venv

$ . venv/bin/activate
5. install flask

$ pip install Flask
6. create a hello world app

create a under myproject folder

from flask import Flask
app = Flask(__name__)

def hello_world():
    return 'Hello, World!'

run app:

$ export
$ flask run