Kotlin Hashing

Hashing is an important concept, it has numerous applications, and it’s at the core of many other computer science concepts.

HashUtils.kt is a very simple, yet very helpful snippet I’ve used in some of my applications when I need some basic hashing. It’s an extension function, one of Kotlin neat features.

package com.isscroberto.onebreath.utils
import java.security.MessageDigest
enum class Algorithm(val code: String) {
SHA1("SHA-1"), SHA256("SHA-256"), SHA512("SHA-512")
}
fun String.hash (algorithm: Algorithm): String {
val hexArray = "0123456789ABCDEF"
val bytes = MessageDigest.getInstance(algorithm.code).digest(this.toByteArray())
val hash = StringBuilder(bytes.size * 2)
bytes.forEach {
val i = it.toInt()
hash.append(hexArray[i shr 4 and 0x0f])
hash.append(hexArray[i and 0x0f])
}
return hash.toString()
}

view raw
HashUtils.kt
hosted with ❤ by GitHub

Usage:

val text = "hello"
val hashedText = text.hash(Algorithm.SHA256)

Reference:
https://www.samclarke.com/kotlin-hash-strings/

One Movie – Exploring The Movie Database Api

I don’t know if I fit in the definition of cinephile, but I really enjoy watching movies and so does my wife, we’ve been going to the movies on a weekly basis for around 4 years and we watch a couple more at home in our free time.

Because of this, the question: “What movie should we watch?” has become a too recurrent question for us so I did what any other software developer would do: I start coding.

I found this really cool api right away: https://api.themoviedb.org

movie_logo

A public api to explore the movie db with plenty of cool features and tons of information about millions of movies. Awesome!

I used the /discover endpoint, you can use it to discover movies sorted and filtered by many parameters like rating, votes, genres, etc. You can look at the specs here.

After a few hours exploring the api and a few days of coding on my free time I had One Movie, a very simple app that gives you random movies for exactly that moment when are finding a hard time deciding which movie to watch and you need an app that decide for you.

logo_round

So, this is what you get.

The app takes you directly to the main screen where you automatically get a random movie, you can see some basic information about it as well as hit refresh to get the next movie if you’re not happy with the current one.

Then there is the filter screen where you can narrow your search and it has the following options:

  • Popular

Popularity is a very important metric in IMDB, it takes many parameters in consideration, such as, the number of votes and views for the day, the number of users who favorited the movie and added it to their watchlists, the release date, the number of votes, among others. One Movie order the movies by popularity and take the top ones.

  • In Theatres

Very simple. It filters movies with a release date less than 1 month old and with theatre release.

  • Year

It filters movies with a release year equal or greater than the specified year.

  • Original Language

It filters movies by the selected language.

  • Genre

It filters movies limiting the search to movies that are within the selected genre. Feel like watching comedy? Horror? Romantic?

  • Vote

It filters movies with a vote average equal or greater than the specified value.

And, of course, One Movie has a simple about screen. That’s it.

Screenshot_20171226-222728.png

Take a look at it 🙂 Leave a comment on how can I improve it and a rating on Play Store would be awesome.

Check the repo and feel free to contribute.