Monday, February 29, 2016

How I have learned 2000 Spanish words in 10 months

Ten months ago I have started learning Spanish on Duolingo. I didn't know a single Spanish word back then. I didn't have any particular reason to learn Spanish. I just wanted to see how the Duolingo app works because my friend Radim told me that it is gamified really well. At first it seemed liked an innocent thing just a few minutes every day in the morning. After a few weeks I got used to it. It gets gradually more difficult especially because you start forgetting and you have to go back and relearn. I started spending more time learning Spanish even from other sources.

Let's jump to the present moment. I keep going. I spend thirty to sixty minutes per day actively learning and about the same time reading a book in Spanish or watching a TV shows just for fun. I know more than two thousand words. I understand about 60 % of both written and spoken Spanish. Those are the boring facts. Now let's get deeper into what worked so well for me.

Duolingo is based on translating sentences. They expect you to figure out the grammar by yourself and it works. At the beginning Duolingo worked pretty well for me. Everything was new. I had to pay a lot of attention to everything. After some time I understood the basic grammar and it became more or less just about memorizing new vocabulary. Then it started to go sideways. It became a mechanical process for me. I just typed the answers without thinking and also I tried to do it as fast possible because I thought that the faster I go through it the faster I am going to learn the language. Boy I was so wrong. In the app it looked all OK. But I wasn't actually able to use most of the it. I wasn't able to use new words when speaking and I wasn't able to recall the new words when reading even though I was able to translate the same word correctly in the app few minutes ago.

It turns out that mindfully paying attention to all the details of the sentence in foreign language is key factor in learning. That way you create much more connections and the new information become easily accessible for you to use it in real world situations. Here are two techniques which help me accomplish it:

  • Say the sentence aloud in your mother tongue. After doing so say it again but now in the foreign language you are learning. There is a huge difference between just reading or hearing something and saying it aloud. Saying it aloud brings a lot of memories into your consciousness. Like memories from your childhood somehow connected to the words some some emotional experiences or maybe some activities you like to do connected to the sentence you just said aloud. In the middle of all this you say the sentence in the foreign language. It gets connected into everything you just have in your conscious memory. This way you build a lot of useful connections to the new words really quickly. That is the important part for being able to actively use the new word later in a conversation. It is going to just spontaneously come up to you whenever you need it the same way as all the other memories came to you when you said the sentence in your mother tongue.
  • Take your time. This goes hand in hand with the previous point. Your brain just needs a few seconds to find the connections.
  • Be creative and playful. After you say the sentence in foreign language say next sentence which you create on your own. It can be related to the previous sentence or you can just take one word and use it. What helps me is that I am usually studying outside and I can use my surroundings and as an input and I can comment on anything I see around me in a language I am learning. This is a higher level and it takes a lot of time and effort so I don't do it with each sentence but just from time to time when I have some idea I stop for a few tens of seconds I try say something with the words I have just learned. Because the sooner I use it the better.
I keep everything I need for learning the language on my smart phone so I can study anytime and anywhere. I prefer to study outside especially when walking. Apart from Duolingo I note new vocabulary into Google Keep immediately after I encounter some new interesting expression. On a regular basis I put the vocabulary into Memrise. Here is my vocabulary named Random Spanish. It also includes pronunciation from Google Translate. I read a book in Spanish book on my smart phone in app FBReader it translates text you don't understand with just one click, so it is possible to comfortably read a text even if you don't understand most of it.

Wednesday, February 10, 2016

Firebase #1: Synchronise User's Private Data

Are you developing Android, iOS or Web app and do you want to store user's private data in the cloud so users have their data on all of their devices without you having to write a single line of server code? In this blog post I am going to present a simple solution using Firebase. Firebase is JSON NoSQL cloud database, it is free if you have less than 100 users online at the same time. I will focus on the Android implementation. This is not meant to be a complete step by step guide. Read the whole article first to get you the idea and then follow the provided links to go deeper.

Since this is the simplest solution to get you started there some limitations:
  • Each user has just his own private data. There is no sharing between users and no public access.
  • Just one method of authentication can be used in the app. e.g. just Google or just Facebook or just Email. Developer can choose any method and hard code it, but then it is not possible for the user to choose his preferred method of authentication.
Both of these limitations can be addressed. I might get to it in future posts. Here is some solution on stackoverflow: How can I login with multiple social services with Firebase? I'm not sure if their solution is secure.

After you go through the Firebase's Android Quickstart you know how to read and write data to and from firebase database, but anybody has access to the whole database so we want implement security rules so each user has access only to his own data.

Each user will have its own private subtree in Firebase database. The firebase url is going to look like this{$user_id}/ anything after the {$user_id} path is accessible only by the authenticated user.

Here are Firebase rules to make it happen. You put them into "Security & Rules" page in firebase dashboard

  "rules": {
    "$user_id": {
      ".read": "auth !== null && auth.uid === $user_id",
      ".write": "auth !== null && auth.uid === $user_id"

These rules mean that the root level path of each object is going to be a user id. Anything nested underneath it can be read and written only by authenticated user which user id is equal to the one in the root path of the object.

I definitely recommend you to read more about Firebase security.

Now I am going to get little bit deeper into Android implementation details.

I implemented Facebook authentication. It was straight forward. I followed this guide: and then this:

Then I decided to switch to Google authentication and it was when the fun begun. It took me a while to resolve a few issues. I also followed the guides here: and here: but it didn't go so smoothly. There is a little catch that you have to create two different google OAuth client ids in google developer console. One is going to be an android application where you put hash of your signing key. Other will be Web application. But the thing which doesn't make sense is that in your android app you have to actually use Web application's OAuth client id. I found it here on stack overlow:

Now you know the catch and you can follow the google guide:

Then after you have your web aplication google OAuth client id and you are using FirebaseUI you have to put the google client id into your manifest. They missed to mention it in FirebseUI readme.

        <!-- Google Configuration -->
            android:value="@string/google_client_id" />

Don't forget to enable your method of authentication in "Login & Auth" section of Firebase dashboard and also put your client id and secret there.

Finally after you successfully authenticate user into firebase you can write into his firebase database:
mFirebase = new Firebase("");