JavaScript Global Imports

01.30.2015

Problems with standard global use in module pattern:

  1. Entire scope chain is checked for non-local variables.
  2. Unclear scope leading to code that is tough to manage.

Solution:

Use global imports by passing in global as a parameter of immediately invoked function. The value is closed up as local variable and can now be modified without worrying about changing the global.

JavaScript Anonymous Closures

01.29.2015

So what if we have a namespace with public properties that we want to make private?

If we want things to be accessible only to the module, we can use an anonymous closure.

Any local variables will be “closed up” in the namespace and made “private”.

We can put everything into an immediately invoked function, and then return an object with the “public” properties.

JavaScript Namespacing

01.28.2015

JavaScript files can often create conflicting global elements, overwriting existing, important data.

Namespaces are not native to JavaScript, but can be simulated by using a variable object as a container.

Everything related to that namespace will be encapsulated within that namespace.

Nested namespacing is also possible.

Trello vs. KanbanFlow vs. Pivotal Tracker vs. Asana vs. Basecamp

01.26.2015

In this post, I am going to talk about various project management tools, and give my completely biased opinions on them.

Trello

I like Trello because of it’s simplicity. It is free. It is easy to create lists and cards. This is what I use to manage all of my personal projects and my freelance projects. It is so intuitive that it doesn’t take more than a minute to explain to a client how to use it. File attachments are also free.

KanbanFlow

I like KanbanFlow for planning out my week. I got the idea from this article. It has a pomodoro timer, but I don’t use it because I’ve found it to be buggy. Still, I estimate tasks by the hour and color code them. One of the nice things is that all of the boards fit onto the screen, making it responsive. This is nice so that you don’t have to scroll left and right to see all of your lists. You can also collapse lists.

Pivotal Tracker

I used Pivotal Tracker during my time at a startup. It’s not free. It has a lot of “Agile” features like point estimation, velocity, etc. It can sometimes be confusing because it will group task items into either current or backlog depending on your average velocity. Pivotal has a lot of features that could potentially be useful if you strictly followed their way of doing things. As soon as you stray from the pivotal way, it becomes like another kanban tool. If that is the case, you might as well use a free one.

[Update 3/5/2015: Just finished reading Scrum: Doing Twice the Work in Half the Time. Now that I look back, Pivotal Tracker follows the Scrum process exactly. You’ll get the most value from this tool if you know and follow the scrum process closely.]

Asana

This one I have the least experience with. I used it for a couple weeks at the startup, but ended up switching back to Pivotal. This is more of a traditional “to-do list” style app. The UI resembles old school Windows applications. It has a lot of features. There are so many buttons and widgets that it actually gives me some anxiety to use this tool.

Basecamp

I’ve never actually used this tool for a real project. I’ve only played around with it. It has the document to-do list style. It has a bunch of features like a calendar. It’s not free. Other than that, I don’t have much of an opinion here, since I haven’t really used it.

Conclusion

These days, I only use Trello or KanbanFlow. Trello because it’s free, simple, and free file attachments. KanbanFlow because it is free and because of responsive UI, more visible color code, and collapsible lists.

HTML5 Geolocation and Ruby Geocoder

01.25.2015

Recently, I needed to figure out how to get the location of the user’s mobile device in order to serve up location specific content.

HTML5 Geolocation feature allows you to get the longitude/latitude coordinates of the user.

This will provide the longitude/latitude location of the mobile device using the device’s native GPS functionality. With the coordinates, I can pass it to the geocoder gem to find out the city, state, country, etc. If we know the location, we can serve up a specific content depending on location.

Sources

http://stackoverflow.com/questions/13831813/mobile-geolocation-with-rails

http://www.rubygeocoder.com/

JavaScript Numbers

01.23.2015

toFixed() will select exact amount of decimals to display.

parseFloat() turns strings with decimals into numbers.

Use both in combination to get exact values in math operations.

parseInt() takes first available integer at the front of string.

Use a radix value to ensure correct parsing. parseInt("021", 10);. This will ensure base 10 parsing.

To test for a number, use typeof AND isNAN()

function isThisActuallyANumberDontLie(data){
  return (typeof data === "number" && !isNaN(data) );
}

Sources

Code School JavaScript Best Practices

JavaScript Brackets

01.22.2015

When you have a one line statement in a conditional or loop, the brackets are optional.

Anything more than one line without brackets will produce unexpected behavior.

To avoid confusion, it’s best practice to always use brackets.

Source

Code School JavaScript Best Practices

Ruby on Rails Render vs. Redirect

01.21.2015

Rendering a template is the final step in the handling of a request.

Redirecting means terminating the current request and asking the client to initiate a new one.

The main reason to redirect rather than render has to do with browser reload behavior. We usually want to redirect after a POST action so that users will not be prompted to re-submit the form when they hit the back button or reload.

Sources

The Rails 4 Way