Daniel Allen Deutsch

Web Developer

Blog

Project #2: My Location

Pushing from Desktop

August 18, 2016
Introduction

I recently left my full-time job in New York. This deserves a dedicated blog post, and I plan to do that once I can properly organize my thoughts.

But a big part of why I left is: 1. I want to spend time traveling and (what I've been calling) 'city shopping'. 2. I want to spend time building all sorts of fun tech projects. Anything that makes me and/or other people happy is the only criterion. Importantly, I'm hoping these projects will also drive learning in new areas for me.

On my About page, it says "Daniel is a web developer that lives in Brooklyn, New York." That's no longer true! I want to update this so that it pulls in dynamically from my current location.

Mostly, I just think this is fun. I like the idea of going somewhere for a weekend, and my website updating automatically. Realistically, there is no obvious benefit. But maybe my family/friends will enjoy having a reliable way of knowing where I am.

The Specs
Initial Plan

I want this to work based on the location of my phone; my phone is always on and always with me. But I don't know much about mobile, so I'm going to build the first iteration using the location of my laptop.

At a regular frequency (every hour?) I will post my location to a remote database. I will then fetch the location with JavaScript on the client-side, on each page load. Easy!

Approaches

This project appears to have 3 or 4 parts. The first is the database, to store my location. The second is the client-side code, to fetch the location. The third is posting my location. If I post all details related to my location, that's it. But if I just post some information, the fourth will be a service that transforms the given information into everything required.

Database

I don't want to be bothered much with the DB. My needs are small—I just want to store simple data remotely. Therefore, it seems ridiculous to set up and maintain a dedicated server.

For this reason, I think Firebase will be a good fit. I used it a while ago for a small project. The major benefits are that: 1. I don't have to manage anything myself and 2. it's free(!) for non-enterprise projects.

Client-Side Fetching

This should be fairly simple. Once the remote endpoint is set up correctly, the location can be retrieved with $.get and the DOM can be updated with $(#city).html(city).

Posting the Location

This will be the hard part. On first-pass, I will write a shell script that uses my current IP address to determine my city and state. Then post that to the remote Firebase DB.

I'm not great with bash, but I believe simple APIs exist to find city/state from an IP. I'm hoping I can accomplish everything with curl.

To run the script regularly, I will use cron to call it every hour 1.

This should work on my laptop. However, it will not transition nicely to mobile. That is, I cannot run a cron job on my phone. And finding the city and state will be more difficult without curl.

But I'll cross that bridge when I come to it. Will I need to build a whole Android App, or does something already exist? I can see just posting my IP address from mobile, and running a service to transform that into city/state. I can either use cron on a remote server or use something like AWS Lambda.

Learning Objectives
The Code

The good news is that it works! About. It's overly object oriented and uses Ruby instead of bash, but seems fine for such a tiny system.

The code for the shell script and the code for the client-side fetch are available on Github 2.

Outstanding Questions
Takeaways
Closing

I'm happy I got this working relatively quickly. I think it's a neat update to the About page.

Getting this working on mobile will be more interesting. I need to do some reading about bash. I will update this post as I continue working on this project.

I'm going to Michigan this weekend, so we'll see if it works!

[EDIT: Rather than updating this post, I wrote a new entry about getting this working on mobile.]


1 a note about cron. I heard the term used for over a year, and always thought "I'm a web developer. That's a tool used by Systems people." cron is now one of my favorite tools. It comes in handy all of the time, and is simple to use. If you're not familiar with it, definitely check it out. It allows you to schedule recurring jobs.
2 one potential gotcha: I'm storing all times in UTC to avoid possible time-travel conflicts.

Have anything to say? Questions or feedback? Tweet at me @cmmn_nighthawk!