Mike Etlinger | Full-Stack Developer

  • About
  • Portfolio
  • Contact

NYC Open Data and The Socrata API

March 29, 2018 Leave a Comment

Still fresh off deploying Grub Grades I want to give a little more info on using publicly available data to build cool projects.

First off, what is NYC Open Data? It’s data made available by NYC city government that has datasets concerning anything from Wifi hotspots to compost drop off and air quality readings.

There’s a lot of cool stuff you can do with the data. For example, as a new feature on Grub Grades, I plan to map out the different restaurant grades via goolge maps just so you can get a nice visual of the grades in your area.

To get started on your own project, head over to NYC Open Data and look through some of the datasets.

There’s plenty of documentation on the API, which uses SoQL or the Socrata Query Language. It has a similar feel to SQL but has a lot of flexibility added. You can find more info here: Getting Started – Socrata API. It’s recommended that you sign up for an App Token before using the API too much, as it will eventually throttle you without one.

What’s really cool is that they let you test out the queries via hurl.it. This helps in adapting your queries without needing a third party solution such as Postman.

Try it out here: hurt.it

Cool, so I hope this was a nice intro to using NYC Open Data. It’s super awesome that we can play around with these lush datasets, but you should also be aware that some of the data will need to be handled in a way that filters out duplicates or other quirks the data might have.

Good luck!

Filed Under: Uncategorized

Grub Grades – A Simple Web App to Look Up NYC Restaurant Grades

March 22, 2018 Leave a Comment

Hey guys! Just deployed my latest creation!

Search for you favorite restaurant and see if it gets a passing grade. Optionally, you can check the latest violation and see if your OCD will win over your desire for delicious food.

Grub Grades

I used the Socrata API to query NYC Open Data which allowed me to look at restaurant grades and look at recent violations. It was pretty straightforward but the query strings got a little tricky. The difficult part was getting only results that included a grade so that I could display the right grade.

Socrata ues SOQL so I’m sure there’s a way to get my results that are unique and also have the latest grade, but for now I’m handling the unique results in the client.

Possible upgrades would be to plot the graded restaurants on a map so you can visualize the A B C’s for NYC =)

Filed Under: Uncategorized

Recursion!

March 15, 2018 Leave a Comment

Recursion!

What is it?

Recursion in its simplest definition is calling a method or function inside of itself. In other words, within a function definition, there is a function call to itself! It’s basically inception….

via GIPHY

Conceptually, we can think of recursion like the opening of Russian dolls. Inside each of the dolls we open, there’s a tiny piece of paper with a number, perhaps we’re adding something or subtracting something. We know we have to open each of the dolls, but we don’t know how many, and only at the end, can we know what the result is.

Let’s not give recursion too much credit though or else we become too afraid to use it.

There are three concepts that you should immediately think about when considering a recursive approach to a problem.

  1. Base Case
  2. Recursive Case
  3. The idea that you’re breaking down a problem into it’s simplest step and doing that step over and over again until you’ve reached your Base Case or “The End of the Line”

The Base Case is a condition that must be met in order to stop the recursive call in your function. Otherwise you will infinite recurse into stack overflow. Think of this as the condition you set in a while loop, that allows the while loop to cease executing.

The Recursive Case is the condition that calls the function within itself. This allows the function to progress to the base case.

Back to our Russian doll analogy. We open the doll, find the number and keep it in the order you opened them, then open the next doll(Recursive Case). After all of the dolls are open(Base Case), we can start adding the last number to the second to last number, then that number the next two and so on until you arrive at the sum.

Recursion goes a lot more in depth when you bring `tail recursion` into the mix. That is passing an accumulator in as an argument to your recursive call so that we don’t need to follow the call stack in order to return the sum.

In the Russian doll example, you would just total everything up as you go, and at the end you would return that as the sum.

Recursion is super powerful, and is easy when you keep the 3 main points in mind, don’t be afraid to give it a try and reach out if you’re struggling with it conceptually.

Filed Under: Uncategorized

Button Challenge Refactor

March 8, 2018 Leave a Comment

Hey guys, I refactored my super verbose brute force implementation and wanted to talk about my approach a little bit.

You can see my previous post here.

But to recap a little bit, I was to parse a string of numbers and operators, where the operator preceded any numbers, and sum them together.

Like this `- 2 – 6 5`

A pattern emerged here so I decided to use regex to parse that pattern out.

In the Class Method `parse`, I’ve used the following regex pattern: string.scan(/-\s\d\s\d/).

This is saying looking for a ‘-‘ sign, followed by a space, followed by a number(1 or more digits) which is followed by a space and again a number(1 or more digits). Then, create an array where only the strings that match that pattern are included.

This pattern is the important pattern, complex pattern, that is the key to solving the challenge. Everything that is a natural number or whole positive number is just going to be added to the sum, but you must follow the Order of Operations on the negative expressions.

In that sense, I then replace the same pattern with empty strings to build the simple sum string. That leaves me with an array of the patterns that matched for the complex expressions and a string of only the simple expressions and in the end they need to be summed together.

And there you have it. A lot less verbose, and easier to follow by separating the two sums into their own methods.

Until next time!

Filed Under: Uncategorized

Button Code Challenge

March 1, 2018 Leave a Comment

Hey guys, just got a code challenge while applying to a software engineering position at Button.

This is pretty cool! Not the most difficult problem in the world, but some definite “gotchas” if you’re not careful.

Here’s the “gist” of the challenge:

So at first, glance, here’s my thought process:

  • We need to know which numbers are negative (-)
  • Let’s not worry about which numbers are positive, we’ll just add everything together in the end(reduce?) after turning the (-) numbers to be negative.
  • We need to split the string with the right regex pattern.(+ or whitespace perhaps?)
  • oh crap, this is harder than I originally thought, haha!

Ok so this is sort of the process of software engineering. Hearing a problem, coming up with a simple ish approach, realizing it’s much more involved that previously thought, and iterating on that process until you have a solid solution.

As I write tests and figure out the best approach I will update the post. For now, I have a simple implementation that’s working for almost all of the test cases, but the most difficult part of this challenge is negative numbers and parsing those correctly to add those negative numbers with reduce.

One thought is to iterate through the string, initialize a `current_operator` variable, and add that current operator to each character in the string. That way, each operator would be added to the corresponding expression, and therefore leave all of the numbers with a + or – to their corresponding value. This would make it easy to use `reduce` to calculate the sum.

Stay tuned for an updated post, complete with the process for test coverage and a JS implementation.

Filed Under: Uncategorized

How To Meta Program A Dynamic Ruby `set_resource` Method In Rails

February 22, 2018 Leave a Comment

As an organizer of a meetup on Flatiron School‘s campus, I meet some interesting people and we do some silly things that are inspired by our founder Avi Flombaum.

Now, one thing that’s really awesome to experiment with in Ruby is meta-programming. Meta-programming is writing code that writes code for you and one of the best examples of that is writing a method that accepts a hash as an argument and assigns values to attributes based on what’s passed in.

This is called `mass assignment` and looks something like this:

If you initialize the user with a hash, it will assign a variable for each key in the hash and then set the value of that variable to the value of corresponding key.

It’s pretty cool. But tonight, we began talking about metaprogramming and I pulled up some code that had been in my github for a long time, waiting to be refactored(so it actually works).

Here’s what I found:

Sweet. I was attempting it, but it didn’t actually work. So tonight we got a bit silly and actually implemented something that worked. The key to this was using `Object.get_const(model_name)` and that made all of the difference.

Here’s a basic version that would need some tweaking to truly work for all controllers.

Since this is so basic, we’d need to account for various controllers with unique pluralizations.

Thankfully, Rails provides the method `singularize`!

There we have it! Something that we should probably never, ever use. But sometimes it feels good to write code because we can.

Filed Under: Uncategorized

  • 1
  • 2
  • 3
  • Next Page »

© 2018 Mike Etlinger
 · LinkedIn
 · Github