Tuesday, September 25, 2012

Mac; iTunes; getting my new Mac to use my external drive's iTunes Media

Recently got a new Mac.  I wanted to be able to access my music library without needing to leave my older MacBook on all the time.  My external drive already has all my resources (the iTunes Media folder location) and my older MacBook had already upgraded to the latest iTunes, so it seemed the process would be easy enough.

First try:

1. hook up external drive to new Mac
2. change iTunes Media folder location to point to external hard drive

Many of you may note a problem already.  It's fundamental to understand the distinction between the resources and the library database.  Hence, the reason why I opened iTunes only to find an empty music library.  Ack!  Where are my files?!

http://www.ilounge.com/index.php/articles/comments/moving-your-itunes-library-to-a-new-hard-drive/

Specifically, the following sections of the above reference were important for me to understand.
  • "iTunes: The Database versus the Content"
  • "Moving the Library Database"
And those sections make perfect sense.

Second try:

1. hook up external drive to new Mac
2. change iTunes Media folder location to point to external hard drive
3. close iTunes on new Mac
4. on old Mac, zip up old iTunes library and supporting files (not the iTunes Media folder that was already on my external hard drive) and transfer to new Mac.  Back up new Mac's iTunes library (just in case), remove and unzip previous iTunes library database and supporting resources to new Mac location.
5. start iTunes again

There's a little waiting time while iTunes does something, but now I'm up and running on my new Mac.  And with not much time wasted.

Friday, June 22, 2012

Troubles pushing code to Heroku

After a little sleuthing, I found one post that seemed to be the very same problem that I was having.  In normal(?) environments, Bundler will accept conditionals in determining whether to install a gem or not.

E.g.,
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i # so that Guard can detect file changes on OS X (Mac)

Apparently, as FreeAssoc states in his post, Heroku doesn't handle the conditionals well, even when those conditionals show up in a non-production block in the Gemfile.

Sure enough, as soon as I commented out the conditional, I was back in business.

gem 'rb-fsevent' #, :require => false if RUBY_PLATFORM =~ /darwin/i # so that Guard can detect file changes on OS X (Mac)

Wednesday, June 20, 2012

Finally getting to know the asset pipeline

For the last year I have accepted the asset pipeline as Ruby 'magic' that just works. I decided it was time to take my head out of the sand and actually understand a little of how it works and, more importantly, how I can leverage it. I would start with these two references; they were key in bubbling up the important concepts.

Then, while I was in the area, I also got a brief overview of Coffee Script and Sass.

Of course, there's nothing like going to the source to get the raw information. The above resources are great at quickly providing an overview from which it may be easier to take advantage of the reference material below.

Here are some of the jewels I gleaned from my experience.

  • files under the app/assets directory consist of manifests (with directive configuration), JavaScript, CSS, image and other resources. The manifests are responsible for grouping sets of assets. It just so happens that out of the box, the application.js and application.css files include everything -- hence why many feel the asset pipeline is just more Ruby 'magic'.
  • Each layout template usually has '<%= javascript_include_tag :application %>'; this truly means that only 'application.js' or 'application.js.erb' will be pulled in. The directives at the top of 'application.js' determine what other js resources will be compiled into 'public/assets/application.js' at deployment. If you require a different set of JavaScript files for a different layout, set up directives for a new *.js file to pull in the desired resources and point to the desired JavaScript 'custom_manifest' in the call to '<%= javascript_include_tag :custom_manifest %>'
  • With the CSS assets, to provide a certain set of styles to an isolated controller and its associated views, namespace the targeted css attributes by setting the id for the tag and including that namespace in the appropriate *.css file. Or better yet, group the css attributes in a *.scss file.

I'm looking forward to now leveraging the true power of the asset pipeline.

Monday, May 14, 2012

CSS Cross browser support for 'display: inline-block'

I had one of those where-have-I-been moments today. I found a new favorite technique in HTML CSS design:
  display: inline-block;
I was briefly discouraged when I realized the code did not seem to work for IE. Then I found Isaac Schlueter's blog, Foo Hack and all is well in the world again.
  display:-moz-inline-stack;
  display:inline-block;
  zoom:1;
  *display:inline;
Even though it brings a whole bunch of new problems, every time I hit one of these incompatibility issues, I can't help wishing there were one browser to rule them all.

Saturday, February 25, 2012

The Adventure Begins

All logic would suggest our course of action is crazy and I submit to you that it does sound crazy. Let me describe to you what's on the other the line.
  • we feel that we should move to CA -- ok... where?! California is a big place
  • we feel that God has revealed to us that we need to move to Atwater, CA
  • I feel promptings indicating that a job will be provided
Let me pause to mention that I believe there is a God and that He cares about each of us, His children, even on an individual level. I believe these revelations come from our Heavenly Father. The fact that God has an interest in my life is more than enough to offset the concerns for why we shouldn't make this move.
  • we start getting our house ready to go on the market; we want to beat the onslaught of foreclosures coming in the spring of 2012.
  • we receive two offers on our WV house in spite of there being short sale homes in our neighborhood
  • we find a house in Atwater, CA that we are interested in buying
Ok; up to this point, perhaps these facts are not that significant. When our home first went on the market (31 Oct, Halloween night), we had a handful of competing homes, perhaps less than 10. By mid January, there were an additional 20, most of which were short-sales. Having the level of interest we had I see as being truly miraculous.
  • we put an offer on a house in Atwater, CA
  • someone put an offer on our house
At this point, the game starts getting interesting. In order to buy the house in California, we either need to be employed in California or buying a second home. Banks don't feel as confident with someone who is self-employed as they do with someone who has proof of consistent employment for many years, so I decide I need to remain employed with my current company at least while we are closing on the California house. While not impossible, it probably throws up red flags for the banks if someone's location of employment is on the opposite side of the country from their primary residence. This means that in order for the bank to give us the loan, we need to buy the California house as a second home.

So, in order for things to work out optimally, we must buy the California home while I am still employed with my current job and while we still own the home in WV. The first contract on the home fell through. That's fine anyway because the buyers expected us to bring $25K to the table and replace all flooring in the house. I realize it's a buyers market, but come on... what's the color of the sky in their little world?! Less than 1 week later we get another offer on our house. A down to earth family who needs us to settle at a price less than $25K than what we owe, but they are willing to take the house as/is. And it's clear to me they understand they great deal that they are getting right now.

* one
* two
* three

asdf

Location:Charles Town, WV

Monday, January 23, 2012

ENV before Ruby

When making environment variables available to a Ruby script, make sure the environment key/value pairs are declared before the call to run a Ruby script.

E.g.,

MY_ENV_VAR=test ruby show_my_env_var.rb

first things first

I probably goes without saying, but when you are starting out with a new project, it is best to get as much of the framework available to your customer up front. Stick with as much bland as possible (e.g., wire frame) so that it's obvious that colors, graphics, etc. are not the focus up front. What good is the fancy shine when there is little functionality.

I spent a good amount of time looking for a tool that I could use to create wire frames that could be easily published and couldn't find one that would generate actual RoR views that could be published. The best tool I found was only for Windows and I use a Mac. With wire frame views in place along with the ability to navigate from resource to resource, it would be very easy to prioritize the pages and add actual functionality/color/graphics to that particular resource.

Active Scaffold is very interesting and is an example of using convention to save time in creating forms based on model configuration. I realize it's asking quite a bit, but it would be nice to have a tool where controls could be drawn/resized/etc and then published to RoR views.

It might be something worth looking into.

Wednesday, January 18, 2012

the basics of textual progress bars

While running through some maintenance of some log directories, I learned a little bit about $stdout and textual progress indicators.

The app I work with logs like crazy. There are time-date-stamped log files all over, products of the much appreciated log roller we use. Obviously, log rolling helps eliminate the need to peruse through an 8+ gygabyte text file. That's good. The accumulation of so many log files, however, get's to be almost as annoying. Just like my commuter car, at some point you can't stand it anymore and it's time to do some house cleaning.

I'm a software developer, and a lazy software developer at that. If there is any reason to code something, I'll gravitate towards creating a script, even to generate lines I can run in my console to tar up log files. There are so many log files to be tarred that I found myself wanting to view the progress since it's no fun staring at a frozen screen.

I use tail -f often to watch log entries being made from the web application I'm working with.

tail -f log/development.log


I can also see what files in a directory were last touched.

ls -lat | head


Wouldn't it be nice to have a script that monitored the directory and let me see those tar archives grow? That much was pretty easy.

while(true)
puts `ls -lat log/archive | head`
sleep(1)
end


But it is ugly. You get entries that scroll you off the page. Then I start thinking about those textual progress bars. They seem to print some character that moves the cursor back to the beginning of the line so that the next print of characters over-writes the last. That would solve my problem with the scrolling.

Ok; again, I'm lazy. I did a little research, but admittedly, just enough to get the results I wanted. So here are some facts/theories:
  1. carriage returns (\r) are different from newlines (\n). When used together, the cursor shows up on the next line. If you only use a carriage return, the cursor returns to the beginning of the line it is currently on.
  2. 'puts' automatically adds a carriage return (cr) and newline (\r\n) to the outputted string. Ok; that's a step in the right direction.
  3. 'printf' may be used to print to the console without a cr or newline
  4. 'printf' automatically buffers, spitting content out to screen only when the script is finished. If we could only force a flush. Including a call to 'flush' doesn't seem to do the trick.
  5. $stdout and $stderr are built in handles to STDOUT and STDERR (go figure!). I'm not sure, but I think that 'printf' is a method associated with Kernel. I do know that calls to $stdout.printf("hello world") followed by $stdout.flush() does work.
We should have everything that is required now. Let's try this again.

while(true)
res = `ls -lat log/archive | head`
$stdout.printf("%s\r", res) #note: don't use a newline; only a carriage return
$stdout.flush() #or you won't see anything,... ever
sleep(1)
end


Ah, much better! Now, since I can't leave well enough alone, I will clean up my output, limiting the output only to the first actual file in the list.

#note: hit Ctrl-c to end the loop
while(true)
#note: there is no check for when no match was found
res = `ls -lat log/archive | head`.match(/^[^\r\n]+[\r\n]+([^\r\n]+)/)[1]

$stdout.printf("%s\r", res) #note: don't use a newline; only a carriage return
$stdout.flush() #note: flush or you won't see anything,... ever
sleep(1)
end


So to sum up, while there are several gems or plugins that offer the nice convenience of a textual progress bar, it all comes down to printing a line that ends in a carriage return (\r) only and flushing the STDOUT buffer.

Here are several references I discovered during the fun little journey I made into the world of progress bars:

http://www.ruby-forum.com/topic/175626
http://blog.dhavalparikh.co.in/2009/04/progress-bar-in-rails/
http://0xcc.net/ruby-progressbar/index.html.en
http://stackoverflow.com/questions/238073/how-to-add-a-progress-bar-to-a-bash-script
https://github.com/jfelchner/ruby-progressbar/blob/master/lib/progressbar.rb

# shortcut for doing sprintf
http://snippets.dzone.com/posts/show/5027