notes.unwieldy: The "Work" Trap

unwieldy:

I find that I—as well as many people I know—fall into a very dangerous trap. I call it The “Work” Trap. What is it? It’s both a procrastination technique and a way of staying in your comfort zone while feeling or seeming productive.

You fall into the trap when you forgo other, perhaps…

Source: unwieldy

Text

If you’re one of the many Ruby on Rails developers who use rvm to help manage your version of ruby and gems in a project, chances are you’ve run into the following error while developing.

"command not found: bundle"

This error most likely occurred because you’ve changed versions of ruby or changed into a new directory with an empty gemset.  Wouldn’t it be nice if there was a way to check if bundler is installed when changing directories and if not, to automatically install it?  Well with a little bit of bash scripting there is.


5 lines of code is all it takes to ensure that bundler is installed and that you’ll be up and running when you cd into a project.

But, I don’t understand bash. Explain it to me

Here is an explanation for those of us who haven’t done much in the way of bash scripting.

Hash is a builtin command to many unix distributions that will print out the location information of a command passed to it.  It works by searching the PATH environment variable.

Building off of hash, the snippet then pipes the output to /dev/null/. We don’t really care about what happens unless bundler isn’t installed.  If an error occurred on the last command we can  assume that the check for bundler failed and that we should print out a message and then install bundler.

And yes, before you ask, it works on zsh.

The code for this is available on my github account.

Text

Learning Thai for the past couple of weeks has been fun.  Here are a couple of the things I’ve learned about the nouns in Thai so far.

Thai nouns are different than nouns in many other languages. They are much simpler. For example,

Nouns don’t have gender ( which means they don’t have articles)

Nouns are uninflected

Nouns are neither singular or plural (which seems  odd at first)

Text

Skype on OSX has a nasty “bug” where when it crashes it can take core audio with it and disable sound for a system. Rebooting OSX will fix this, but that isn’t really a viable work around for me sometimes.

After a couple of quick searches online, I was able to put together a command that will kill all core audio connections and let osx take care of bringing them back online.

sudo kill -9 `ps ax|grep 'coreaudio[a-z]' |awk '{print $1}'`

Text

So the past couple of weeks I’ve been trying to learn Thai by memorizing words (as my girlfriend puts it, at random) and this doesn’t seem to be working very well. After taking some time to reflect and remembering a story a friend of mine told me (about learning Chinese and one of the best days was when he learned what the word for meat was) so I figure I should start off by learning some words that will actually be helpful in Thailand for my very existence.

อาหาร  - food; meal; diet 

หมู       - pork

เขียง     - cutting board, chopping block; fresh? (seen it written in เขียงหมู)

เนื้อ      - beef; meat of any animal (huh? This seems a bit odd).

เนื้อปลา - fish meat (well I guess there is that whole เนื้อ is meat thing)

แกง      - thai style curry

ข้าว      - thai

ผัก       - vegetable

พริก     - chili peper

Text

I had a pretty awesome class today where I learned a lot thanks to my awesome Thai teacher.

Asking questions in Thai correctly is something that should be easy but has evaded me to so far.

หรือ - Is the Thai word for “or”.  By using this word, we drop the question particle ไหม from the end of  a sentence as it’s understood to be a question.  Pretty neat!

Adjectives come after the noun that they are describing. This is the same as Spanish.

Ordinal numbers are dead simple in Thai. All one has to do is prepend ที่ to a number and bam, it’s ordinal. (ex, ที่เก้า  is ninth)

Text

For the past couple of weeks I’ve been working on optimizing a pretty large app that runs on Heroku. This has given me plenty of opportunities to research and try out ways to optimize a site running on Heroku.

  • Remember that ajax calls will each use a dyno. This can be huge on a javascript site.
  • Prune the gemfile, move anything you can to development / test. This will keep the slug small and let the app boot faster (faster deploys!)
  • If you on an older stack (pre -cedar ?) be sure to disable development and test gems as you won’t need them in production. (On this app, the slug went from ~68 - 51 MB, not bad for a couple of minutes of work).
           heroku config:add BUNDLE_WITHOUT="development test"
  • While trying to shrink the size of the app slug, take a look at using .slugignore (http://devcenter.heroku.com/articles/slug-compiler). Anything related to specs / tests, or design comps are a good first start. 
  • Use Http Caching
  • Use New Relic to find slow parts.
  • Be sure to minimize file size and count of assets (Javascript and CSS files). Since this is a rails 2.3 app, we ended up using jammit / jammit-s3.

This list will be updated as I spend more time optimizing the app.

Text

Getting random array of records using DataMapper is pretty easy once you know what to do. First one must require dm-aggregates. Once that is done, it’s as easy as:

@notes = []

3.times do 
  @notes << Note.get(1+ Note.count)
end

This will grab 3 random records out of the database and push them into the @notes array. This example assumes your model is called “Note”.

Text

So this was a cool trick I learned today.

Rake allows you to chain rspec commands. So lets say you want to drop the database, rerun migrations, seed and then run specs at the end. It’s now as simple as:

rake db:drop db:create db:migrate db:test:prepare spec

There is one caveat to this though.

There appears to be some funkiness with how rails is loaded. In a couple of the apps I’ve worked on, chaining db:seed to the end doesn’t work. It tends to break up saying methods haven’t been defined.  In my specific case, the attribute was defined initially  but was  later deemed superfluous and removed. Rails seems to be break and never recognize that this later migration had been run.

There is a pretty simple workaround for this. Just start a new command at the end. While it’s not quite as succinct, running:

rake db:drop db:create db:migrate; rake db:seed db:test:prepare spec

will do the job just fine.