The Execution 💻
LuÃs Silva
Posted on January 11, 2021
I left you with nothing but an idea in the previous post. Now, I will present to you the outcome. We will go over some pain points and lessons learned.
I divided this post into N sections:
- user authentication The Good
- user image uploads The Bad
- geolocation The Ugly
User authentication
For this hackathon, I decided to go with python. To someone on a tight schedule to develop something nothing better than the one and only Django. This beast of a framework can do it all and once again, it didn't fail me. They call it "The web framework for perfectionists with deadlines." for a reason.
However, I am not here to teach you how to use Django since there are a plethora of options on the Internet that would do a better job than me.
But I need to give a big shout-out to one plugin in particular: django-allauth. If you thought that working with Django was easy, imagine working with a plugin that completely sorts authentication for you. Bye, Bye old user Model from Django! Hello, OAuth2 from all your favorite providers.
Using it was a breeze, the pure epitome of what prototyping should be all about. If you find yourself in the need of an authentication solution, go and take a look. And yes, it is as easy as it looks.
Note: I am not in any way shape or form associated with them 😇 but it was a really nice experience
User image uploads
What about those pesky images? Let's be honest, no one likes to deal with static files and images and whatnots...
If only life could be just a big JSON file, no images, no content distribution networks... But life ain't like that...
If dealing with images was already a nuisance, imagine not being able to upload them to the file system.
Since these new platforms appeared, like the Digital Ocean one or Heroku appeared, that we are confronted with the question: where to store my pictures? Do I need another service for that? Why is this so hard?
As you know, the issue is that these platforms, based on dockers and so on, can restart your "image" at any time. This means that anything you stored outside of your "image" is not persisted on system restarts.
Tough luck, they said! Do a micro-services architecture! Bleh... Microservices were invented by start-ups that didn't want to upgrade their apps from the free tier.
Joking aside, for me this is a big pain point. But not anymore!
During development, I already had to set up one database for the rest of my data. Why not use this Database to store my images in some binary field? I bet some of you got a burning sensation behind your ears because of what I wrote just there. But stay with me!
Just look at this page.
SQLite reads and writes small blobs (for example, thumbnail images) 35% faster than the same blobs can be read from or written to individual files on disk using fread() or fwrite().
Maybe it's not such a bad idea. 🤷
This is a hack a ton after all!
Geolocation
When you want to do anything related to geolocation you already know that you are serving to yourself a big blob of work. No one likes to deal with coordinates. It's worst when you want to get to query your date based on location. You can't use simple math because the earth is round and difficult. You try to use database specif functions just to see that you don't have that plugin installed.
But today I am here to share with you a little tip. Some might find it very ugly. Others will give it the credit it deserves.
Geohashes! A god sent solution to all your location issues.
The way it works is by subdividing the globe into sections again, and again, and again.
This gives you a way to pinpoint a location in the world with any precision you want. It also provides a way to get nearby locations using only string operations. It's simply magical. Try them
Conclusion
I hope you can find some interesting things in this post, maybe they will serve you in another hackathon!
Until next time...
Posted on January 11, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.