Ember.js Lessons Learned Retrospective

Ember.js LogoWhile googling for some syntax on Ember.js, I came across this incredibly helpful list of “lessons learned” from Landon Noss aptly named “Things I wish someone had told me when I was learning Ember.js“. He documented 28 tips learned from the battlefield. I love lists like that: Concise lessons distilled down to digestible bullet points, enough for others to go through the same troubles and speed up the learning curve. Kudos to Landon for the awesome list.

Just in case the article, the link or the site disappears, here’s a PDF version I generated for safekeeping.

Debugging Ruby 2.1.x and Rails 4.1.x with RubyMine

One of RubyMine’s strongest features is its debugging tool. But it’s always been finicky to get it working for me. I finally got it to work since upgrading to Ruby 2.1.x. The situation was complicated by Ruby 2.x not yet supported by debugger gem… etc.

To get everything to sing in harmony, here’s what I used:

And that was it!

Javascript Structs and ImmutableStructs

This is a pretty cool article on implementing structs and immutable properties & objects in Javascript. Data structure like this makes it possible to construct and serialize user roles and capabilities objects on the client-side user Javascript that prevents users from tempering with the view. Bad ass!

Here’s a PDF backup of the article just in case the site or URL goes blind. You can’t be too safe!

Upgrading to Mac OSX Yosemite

Mac OSX Yosemite became publicly available today. Since my Mac is in-between projects, I decided to take a chance and upgrade.

I ran into three problems for my Ruby on Rails set up:

Other than those 3 things, pretty much everything else has worked as-is out of the box. I enjoy the crisp look of the fonts and icons in the new OS. And hopefully nothing crazy will happen going forward.

Deploying Chef without a Chef Server

chef-logo

Chef is a great tool. I really love it. But to take full advantage of it, you need a Chef server (either build one yourself or have it hosted with Opscode (which we did at my last job). For small businesses and/or personal server(s) of very small scale (I’d suggest up to 3 to 5 servers at most), a nifty tool like LittleChef can really be quite useful. But if servers you manage ever grows more than a handful, I’d highly recommend hosted service like Chef to keep your sanity.

SuperHero.js for Javascript Best Practices

Javascript has been evolving way more quickly than I have been able to keep up. I’m still behind on some of the recommended best practices and modern techniques. Luckily someone had the good sense of putting up and documenting these things. I hope s/he/they keep up the good work to spare the rest of us.

This wonderful resource is SuperHero.js. It keeps up-to-date a list of resources on best practices and latest techniques in the world of Javascript for the rest of us peasant coders. Kudos to the site maintainer(s).

Duck Typing in Javascript

PHP was the first programming language I learned. But Ruby has been the language that I love. One of the patterns Ruby champions is the idea of Duck Typing. It’s a great way to avoid using if/else statements too excessively. In Javascript, this can be easily implemented as well. This article does a great job explaining it with some sample code. It’s a good thing!

Ruby’s #length vs #size vs #count Methods

Before googling for the article, I knew going in that .size is an alias to .length. But I didn’t know there was more to the story. And what about .count?

Here’s what Josh Susser wrote verbatim:

In Ruby, #length and #size are synonyms and both do the same thing: they tell you how many elements are in an array or hash. Technically #length is the method and #size is an alias to it.

In ActiveRecord, there are several ways to find out how many records are in an association, and there are some subtle differences in how they work.

* post.comments.count – Determine the number of elements with an SQL COUNT query. You can also specify conditions to count only a subset of the associated elements (e.g. :conditions => {:author_name => “josh”}). If you set up a counter cache on the association, #count will return that cached value instead of executing a new query.

* post.comments.length – This always loads the contents of the association into memory, then returns the number of elements loaded. Note that this won’t force an update if the association had been previously loaded and then new comments were created through another way (e.g. Comment.create(…) instead of post.comments.create(…)).

* post.comments.size – This works as a combination of the two previous options. If the collection has already been loaded, it will return its length just like calling #length. If it hasn’t been loaded yet, it’s like calling #count.

Speed Up Wake from Sleep Time on Mountain Lion

I bought a very beefy MacBook Air this summer. But I was frustrated with how slow the machine’s wake-from-sleep time was whenever it’s been in sleep mode for an extended period of time. For the longest time I just couldn’t figure it out. But as it turns out, it’s a new “feature” designed to make the batteries last longer.

Basically after certain number of hours, in order to save on energy, Mt. Lion saves most of the content in RAM to disk, thus making the wake up taking much much longer than desired. Here’s the blog I found with instructions to change that.

And here’s the instruction just in case. Open your Terminal via Applications > Utilities > Terminal.app, and issue the following command:

sudo pmset –a standbydelay 43200

43200 is seconds, which is 12 hours. I almost always never leave the laptop unused more than 12 hours, so I set mine to 86400, which is 24 hours. To find out what the current setting is, issue this command:

pmset -g

And there you have it!

Resources for Working with Objective-C’s Core Data

I started dabbling with building an app in Objective-C and Xcode recently. And Core Data seems to be a nice way to work with persisting data across app launches. But its learning curve is notoriously steep (Apple’s own documentation doesn’t help at all).

But Techotopia has a nice and short overview of what Core Data is and how it works in a way that’s not intimidating. But the best source for me by far is “Core Data for iOS and OS X with Simon Allardice” from Lynda.com. I’m a visual/audio learner. And the best way for me to learn is usually through a Youtube video or some clips from Lynda’s web site.