How to Write a Better Git Commit

Code reviews and assessments are two of the most useful parts of the Learn Verified program. A key thing that I learned during my Rails Assessment a few weeks ago is that potential future employers are going to be critically looking at your GitHub commit history. Well I knew that people would check out my GitHub of course, but it helped to know what others are looking for.

Now there are quite a few different schools of thought about how to write the best (aka most useful to other people checking out your code and your future self as well) commit message, but I’ll try to summarize what I’ve learned via assessment conversations and comparing notes.

One thing that I heard that surprised me is that employers will look at your commits and actually compare your changes with the description. Do they match? Or are there other things in there that you forgot to mention? Are the commits regular? I will admit that in the past I was not great about this. In the past I was committing willy-nilly. At certain points I would be like “Oh I haven’t committed in a while, better take care of that”, and then I would try to remember what I’d done since my last commit. Bad idea!

DOs

  • Commit early and often. Perhaps every 5 – 10 minutes. Something is worth committing when you’ve been really typing for a bit.
  • Consider making your commits feature-based. So for example:
  • Set up User authentication with Devise
  • Move jquery and bootstrap from script tags in layout erb to gems in asset pipeline; fix the issue of nav button dropdowns not working after creating a new attraction by adding document.ready(toggle) to js
  • I haven’t tried this yet, but have a subject line and a body, leaving a line in between for readability.  Capitalize your subject line, which is really a short summary of the change (50 characters or less). Use the body for explanation. Blank lines between paragraphs. Thoughtbot suggests ditching the -m flag altogether, to get yourself in the right state of mind.
  • Probably most important: Explain why the change was made, how it addresses the issue, any design decisions, and any foreseeable side effects the change will have.
  • I suppose this is a syntax and style thing, but it seems like most people prefer the imperative tense as it implies a command and matches Git’s tense. So, “Fix” or “Change” instead of “Fixed” or “Changed” for example.
  • Wrap your commit messages to 72 columns to prevent overflow. This is another thing I haven’t tried yet.
  • Say you thought you had fixed an issue during a certain commit. Say you realize that no, this time you’re really fixing that feature. Instead of committing “Fixed Feature X for real this time”, you can go back and amend your previous commit. Check out git commit –amend.

Phew! That was a lot, but if you think about it, it’s mostly common sense.

10 Fun APIs to Inspire Your Next Project

I’m currently working on my final project for Learn Verified- a single page app with an AngularJS front-end and a Rails back-end. Like I’ve said before, coming up with a project idea is often one of the biggest hurdles of these assessments. For my current project I found myself browsing APIs and hoping to be inspired. Here are ten fun APIs I came across… maybe you’ll find one to use for your next project! 🙂

  1. 1. San Francisco OpenData – OpenData is a treasure trove of information. My favorite data set details Film locations in San Francisco.
  2. 2. NASA API I’m not sure exactly what NASA offers, but hey, it’s NASA!
  3. 3. We the People API – The White House has a petitions API! They’ve also laid out API Standards for government created APIs. A little more info: Using our API, you can bring We the People petitions to third-party platforms (including other petition services, personal blogs, and websites) in order to spread the word and help gather even more signatures. Any signatures collected this way, once validated, will count towards the signature threshold needed for a petition to receive an official White House response. Think of our API as a valuable tool for building community support around an initiative — it can help get a petition in front of more eyes, more quickly, with exciting results. 
  1. 4. Pokemon API – Finally; all the Pokémon data you’ll ever need, in one place,
    and easily accessible through a modern RESTful API. Gotta catch ’em all!
  2. 5. Marvel Comics API – The Marvel Comics API allows developers everywhere to access information about Marvel’s vast library of comics—from what’s coming up, to 70 years ago. Search 70+ years of comics by character, series, creator… OMG
  3. 6. Yoda Speak API –Turn your sentences and webpage into Yoda-speak. This one is pretty silly, I’ll admit.
  4. 7. The Cat API – Cat pictures!
  5. 8. Audiosear.ch API –Search for words and keyword tags in a full-text index of top podcast and radio shows. Get web profiles for podcasts, and find audio about trending topics, and audio recommended by influencers like Ira Glass. 
  6. 9. BreweryDB API  – Beer beer beer!
  7. 10. National Nutrition Database API – Our API provides REST access to the National Nutrient Database for Standard Reference (NDB) . It is intended primarily to assist application developers wishing to incorporate nutrient data into their applications or websites. That sounds awfully dry, but I think it could be super useful. Bookmarked! 

If none of these APIs excite you, you can search Programmable Web’s API directory by category & protocol. Want a little handholding? Codecademy walks you through working with several popular APIs(Twitter, YouTube, SoundCloud, etc.)

jQuery Project: Vacay+

I’m at the point in my program where all I’ve got left are projects and the corresponding assessments. Awesome and terrible. Awesome because projects are where the learning really happens, and where I tend to get into a flow. Terrible because project time is usually when my ego takes a hit. My track record for amount of time spent on projects has been all over the place. Would it take me a day or two to finish this project (Sinatra)? Or 3 weeks (Rails)? Also, the assessments with Learn instructors have been immensely helpful, but I get a bit nervous. So I tend to schedule my  assessments a ways out and over-prepare with my review of the material.

If you read my Rails assessment post, you might remember that my next steps were to extend the functionality of my Rails project with some jQuery magic. Hrm. Okay, not gonna lie, it took me a while to figure out what they were asking for, as each of the requirements didn’t necessarily ask for an additional feature, it seems like they were mostly describing specific design choices in order to implement the first couple of features.

Here are the Specific Project Requirements and my choices:

1. Must render one show page and one index page via jQuery and an Active Model Serialization JSON Backend. 

I had multiple models to choose from (Attractions, Destinations, Users, Trips), but since vacation planning was the whole point of my app, trips seemed like the obvious choice to work on. I wanted to be able to reveal a little bit more information about a trip on the index page, and on the trip show page I wanted to be able to cycle between all trips with a next button, for inspiration.

  • *Trips Index page has a “More info” link that expands a section under the trip to show the trip’s city, start date and end date.
  • *Trips Show page has a “next” link which updates the page by showing the next trip.

2. Must use your Rails API to create a resource and render the response without a page refresh 

This confused me for a long time until I went back through the end of the curriculum. Then I realized that it probably meant I was supposed to use AJAX post to create a new object. I chose to create a new attraction.

  • *Via the Attractions page, you can create a new attraction (and associated destination and trip, which was a feature of my old app as well), and it will show it to you on the same page by exposing the new data in a hidden div, with no refresh.

3. The Rails API must reveal at least one has-many relationship in the JSON that is then rendered to the page.

  • *Index page – a User has many Trips.
  • *Show page – a Trip has many Attractions.

4. Must have at least one link that loads, or updates a resource without reloading the page.

  • *Index page – has “More info” link that loads … more info
  • *Show page – “Next trip” link 

5. Must translate the JSON responses into Javascript Model Objects. The Model Objects must have at least one method on the prototype. Formatters work really well for this.

This part confused me as well.  I guess they were asking for the JSON responses to be turned into JavaScript objects first before the updated data was rendered to the page. So for example I’d hit the page for trip information (in JSON), and then take the info I needed to create a JavaScript Trip object. Then I’d take that object and use it in the rendering of the information. Also, I’d have to add a method to the prototype. Easy enough.

  • *Trip has the countdown() method
  • *Attraction has the formatUrl() method

Anyways! Here’s a walkthrough of my updated project.  

Read more

REST is BEST

REST? Wut?

This is embarrassing to admit, but a year or so ago, I didn’t really know what REST was. I remember that I was poking around the Twitter developer documentation, trying to figure out how to get a certain location’s Twitter trends. Based on keywords alone, GET trends/place looked like it was what I needed, and it was what I eventually used, but at the time I didn’t truly understand how to work with API endpoints. I was just bumbling along, trying to get my one little piece of data. I didn’t see the patterns.

Anyways, embarrassing. I can laugh about it now because REST is awesome!

So… what is REST? REST stands for REpresentational State Transfer. It’s an architectural style for how systems can communicate with one another. One key differentiator of REST is that it’s “resource based” instead of action based. What’s a resource? It’s generally anything that you want to provide access to in your web app/service. That’s a pretty broad idea, but it’s easiest to think in terms of nouns. Here are some examples of resources from my recent Rails project, which was a vacation tracker: there’s a “trip” resource, “user” resource, “destination” resource, and an “attraction” resource.

What is RESTful routing?

So far in my learning, REST has come up most often in routing my web apps. Apparently, back in the wild west days of the Internet, there were no conventions in place for handling URLs. A URL for creating a new blog post could be “www.bloggy.com/draft-new-post” on one site, and “www.wonderblog.com/new-blogpost” on another site.

RESTful routing uses a combination of HTTP VERB & URI. This design leads to a predictable mapping between the URL resource & the corresponding controller CRUD actions. This consistency makes things better for everyone, users and developers alike.

Continuing with my project example, this means that I can get and send information about each of these “resources” by using specific combinations of VERBS & URLS. This is nice because you can reuse the same URL for multiple needs. RESTful design makes for cleaner, shorter, and more predictable URLs. Rails is all about conventions, so it’s no surprise that Rails makes it easy to implement a RESTful design pattern.

There’s seven possible RESTful route options available, to correspond to seven controller actions.

As a refresher, the  CONTROLLER ACTIONS include:::

  1. Index – shows an index page for the resource
  2. Create – creates a new resource
  3. New – renders the page/form for creating the new resource
  4. Edit – edits an existing resource
  5. Show – shows a specific/individual resource
  6. Update – updates an existing resource
  7. Destroy – deletes the resource

 

And the HTTP VERBS used include:::

  1. GET – this method retrieves data
  2. POST – sends data (via forms for example)
  3. PATCH/PUT – updates existing data
  4. DELETE – deletes the record

 

And here’s what the seven RESTful routes looks like in my Rails app for the Trip resource:

HTTP Verb / URL path / Controller action

  1. GET            /trips                   # Index – Show all trips
  2. POST          /trips                  # Create – Create a new trip
  3. GET            /trips/new          # New – Renders the form for creating a new trip
  4. GET            /trips/:id/edit      # Edit – Renders the form for editing an existing trip
  5. GET            /trips/:id              # Show – Show a single trip
  6. PATCH       /trips/:id              # Update – Update a trip
  7. DELETE     /trips/:id              # Destroy – Delete a trip

When I was first learning about the routing conventions it was a bit overwhelming, but you basically just have to see examples of this over and over again to get it. When you finally do, you’ll love REST too.

Here are a few more helpful and in-depth resources:

Rails Project: Vacay

It’s been a while since I’ve shared a project on here, and that’s because I have been wrestling with Rails since then. Oh Rails, it’s been real. Every section has had its challenges, but Rails was like little mind explosions every other day. It’s an incredibly powerful framework, you just have to learn its patterns, which took me a while.

tl;dr, here’s a quick video walkthrough of the simple vacation tracking app I built with Rails, OmniAuth, and Devise. I am kind of slow and rambling through this ~ 9 min walkthrough, so feel free to watch on doubletime! 

Read more

Scroll To Top