Building a GPA Calculator in Angular.js

I’m awed almost daily by the simplicity and elegance of Angular.js. By eliminating all of the DOM access syntax we’ve come to take for granted in jQuery and friends, and by giving any element on the page a live, two-way data binding relationship with your business logic, Angular lets you create anything from simple widgets to full-on Single Page Applications with the fewest lines of code possible.

I recently created a live GPA calculator as part of a large SPA I’m working on in my day job, but have boiled it down to its bare essence for this widget demo. Try changing the dropdown options here and watch the GPA calculation change in real-time:

View html | View script

In this example, we assume that a student’s current course load comes in over the wire with course names and units. We iterate over the course set and, for all courses being taken for a letter grade, multiply the numeric weight of a predicted grade by the number of units. Those scores get added up, then divided by the total number of units. When a new grade estimate is selected from a dropdown, we need to recalculate the whole aggregate. Let’s step through it.
Continue reading “Building a GPA Calculator in Angular.js”

Tweetbot Bookmarklet for Chrome

Despite a few quibbles, I’ve pretty much fallen in love with the desktop Twitter client Tweetbot. But the one thing I really missed from the official Twitter for Mac client was a good browser bookmarklet for Chrome, so I could start a new tweet from the current web page’s URL and document title.

I did find one referenced in this review, but it was DoA in Chrome – does nothing when clicked. With a bit of monkeying around, I’ve modified it to get along with Chrome:

javascript:window.location='tweetbot:///post?text='+encodeURIComponent(document.title)+encodeURIComponent(' ')+encodeURIComponent(window.location.href)

To install: Copy the code above to your clipboard. Create a new bookmark (of any page) and edit its properties. Paste over the URL with the contents of your clipboard. Save, and Bob’s your uncle!