Archive for the ‘Uncategorized’ category

Resynching the clock on a guest Ubuntu VM

October 19th, 2011

Thanks to MKo who answered this question:

http://stackoverflow.com/questions/5098333/vmware-time-sync-problem-ubuntu-guest-on-windows-7-host

If you find that your Ubuntu clock continues to drift, despite having installed the vmwave-tools, here’s a command to fix it.

sudo ntpdate ntp.ubuntu.com

Why rip this off?  Because I remember the URL of my own blog a lot better than 5098333.

Jobs vs. wealth

May 12th, 2011

As Nancy Pelosi so succinctly put it however long ago it was, “Jobs! Jobs! Jobs! Jobs! Jobs!”  While she may be an Apple fan, I don’t think that is what she was getting at.  ”Jobs” is the hot political buzzword du jour.  And it’s not surprising, what with the recession and all.

But is the focus in the right place? Is creating a job all that big of a deal?

I think it isn’t.  Jobs should not be the end goal.  Wealth should be.  If jobs are all that matter, then there’s nothing wrong with President Obama massively expanding the number of federal jobs.  But there is a big problem with doing just that.  Let’s explore why that is.

Human beings basically need food and water to survive.  Shelter is a nice plus, especially when it’s cold out, and clothes are nice too.  The trouble is that these necessities don’t spontaneously exist in nature in quantities sufficient to sustain the nearly 7 billion people living on the planet.  Raw materials are nice, but without effort they remain just that– raw.

So we have farmers.  There’s 1 job.  Not everyone wants to farm, so we have tailors, let’s say.  There’s a second job.  The farmer’s labor changes nutrients in the soil, water, and energy from the sun into food.  He gives the tailor some of that food in exchange for some clothes, and everyone is happy (we ignore the advent of currency in our discussion as it isn’t relevant to the topic at hand).  Both of these jobs produce wealth, where wealth is defined as “goods and services useful to man’s survival.”

But then along comes the administrator.  That’s job #3.  As more and more people interact with each other, you need to have some administrators to basically keep the actual producers free to produce.  That’s the essence of a good manager in software engineering anyway.  Leave the coders free to code.  Job #3 is not a waste, so long as his presence frees up the farmer and the tailor to produce more goods.

Now let’s suppose that the farmer and tailor don’t live in the same town.  Job #4 is the trucker.  This job also facilitates the production of wealth, because without him, the farmer couldn’t get his excess food to the tailor and vice versa.  The farmer would produce enough for his own consumption, and he would be naked;  the tailor would make enough clothing for himself, and he would be hungry.  Because of the trucker’s labor, more food is produced, and more clothes are produced.

So up to this point, the number of jobs is directly related to the amount of wealth.  Up to this point.

Where all of the politicians go wrong is that they think that by being able to report a higher employment number, everyone is happy.  Government is really good at making Job #3 type jobs, that is jobs that don’t directly produce anything.  At least not where people are free to own property.  FDR created the program where people would dig a ditch and then others would come fill it up.  Oh wow, 2 jobs!  But at the end of the day, you still had a flat field with no ditch.  While it is better to put people to work doing something before getting a handout, this type of job does nothing to help the economy.  There is no net gain of goods and services.  You just have more resources consumed with no new wealth relative to the number of consumers.

I want to see politicians talking about building wealth.  They don’t, because creating wealth is something politicians can’t do.  If they could, they wouldn’t be politicians.  They can encourage wealth creation, and they would do so by not interfering with the farmer and the tailor, so long as these 2 honor their contracts and don’t cause harm to others.   But instead they create tax codes and regulatory mine fields that rival a modern-day operating system’s source code in complexity.  How many millions of dollars are spent each year on TAX COMPLIANCE?  That’s wealth that could have gone into building houses or growing food, thus increasing the number of each relative to those who want them.

So jobs are nice in that they are the natural result of wealth.  But it is quite easy to create jobs without creating wealth, as President Obama has so aptly shown.  That is nothing worthy of applause.

Deprecation warnings in Rails

March 22nd, 2011

Are you working on an ever-evolving code base? Did your project start with an initial engineering effort to fix a specific problem / explore the solution space? As requirements are more fully understood, are you increasingly annoyed with the older code to support different data formats and the like? Do you want to get developers and others to stop using those old formats?

Well, you too can have access to what Rails uses to put deprecation warnings in the log file.

ActiveSupport::Deprecation.warn("Stop calling me!")

It of course takes a good team policy to require all such warnings to be removed, but I was delighted to find that this is readily available and usable for my own deprecation warnings. It sure beats using Rails.logger, because the intent is clearer, and such warnings will get shut off when all deprecation warnings are turned off anyway.

Background color to Apple’s “Novel” Terminal color scheme

December 14th, 2010

I like this color scheme and wanted to replicate it in Ubuntu (I love Ubuntu, but cannot read code in vim windows with the default color scheme). Apple doesn’t make it easy to get the hex code for the Novel color scheme, but here it is in all its glory:

#DFDBC3

Validation gotcha (before_save not being called)

October 18th, 2010

So once I figured it out, there was a generous *facepalm*. Nonetheless, in case you’re struggling with the same problem, here it goes.

I had a before_validation callback on an ActiveRecord model. I was running in test mode using Shoulda and FactoryGirl, so I figured those 2 gems had something to do with it. Then came the humble pie.

I also had a validates_presence_of on the model, and it was getting called before the before_validation callback. The test wasn’t setting that attribute, so naturally I never got to the callback.

Once again it was not a cloud if improbability that caused the universe to collapse around me. It was a bone-headed error.

Rails + WordPress (at the same time)

June 1st, 2010

It is a Sin to be a “Rails programmer” and not use a blogging engine you wrote yourself and especially in Rails, but there are cases when one’s available time is more important than one’s soul.

This particular case assumes you use shared hosting.  That’s probably another bad thing, but whatever.  Also, you need access to your public_html folder’s .htaccess file.  In fact, this whole setup is so host-specific that you might find it worthless.

Starting over.  Shared host.  public_html folder. Apache. Your host routes traffic to your app by rewriting your requests via a proxy to a specific port.

Now let’s say you have the domain www.domain.com.  Your host does something like:

RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$

RewriteRule ^(.*)$ "http\:\/\/127\.0\.0\.1\:12%{REQUEST_URI}" [P,QSA,L]

Note: port numbers have been changed to protect the innocent.

This basically just says “if a request hits me and the host matches your domain, I’m gong to proxy it on to myself on a different port.”  The webserver runs a request against itself on a different port, which presumably is picked up by whatever handles your Rails application.

Well, you want your blog to be at http://www.domain.com/blog.  That unfortunately does contain your domain in the HTTP_HOST.  Which means Rails will try to serve up your blog.  Which means it will fail or, if you actually have your blog in your app’s public folder, will serve up your .php files as raw text downloads.

Solution:

RewriteCond %{REQUEST_URI} !^/blog/(.*)$
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ "http\:\/\/127\.0\.0\.1\:12%{REQUEST_URI}" [P,QSA,L]

We add an additional condition to our rewrite requiring that the actual path requested (Apache’s REQUEST_URI expands to that) NOT match “/blog/” followed by pretty much anything.  This will get your webserver to handle all of these requests as if your Rails app weren’t there, which is what you’re going for anyway.

This isn’t limited to WordPress.  And note that whatever you are trying to run needs to be in your Apache DOCUMENT_ROOT folder.  That could be like “public_html” or something.  I don’t know the answer to that for you.  You CAN work around that with other directives, but that is beyond the scope of this entry.

Rails 2.3.5 doesn’t play well with Rack 1.1.0

February 16th, 2010

Ever get this gem when running a Rails 2.3.5 application with Thin?

/Users//config/../vendor/rails/railties/lib/initializer.rb:271:in `require_frameworks': can't activate rack (~> 1.0.1, runtime) for [], already activated rack-1.1.0 for ["thin-1.0.0"] (RuntimeError)
from /Users//config/../vendor/rails/railties/lib/initializer.rb:134:in `process'
from /Users//config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
from /Users//config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
from /Users//config/environment.rb:13
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/rack/adapter/rails.rb:31:in `load_application'
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/rack/adapter/rails.rb:23:in `initialize'
... 6 levels...
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/thin/runner.rb:139:in `run!'
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/bin/thin:6
from /usr/bin/thin:19:in `load'
from /usr/bin/thin:19

Disappointing to be sure, but there’s a simple fix I found here.  Thin will try to load the latest version of Rack that you have installed, but Rails specifically asks for 1.0.1.  You can’t have 2 versions of it running at the same time, so RubyGems pukes.

The simple solution is to uninstall Rack 1.1.0.  If that isn’t an option for you, dang.  There’s always this rails ticket you could go fix and make a big name for yourself in the community. ;)

How to freeze gems in Rails

February 1st, 2010

http://blog.logeek.fr/2008/12/23/how-to-freeze-gems-with-rails-2-1

shoulda and factory_girl not cleaning up db between tests

December 22nd, 2009

Wow, this one was a doozy. I recently (yesterday) had my first introduction to shoulda and factory_girl for testing. I’m torn as to whether or not fixtures are the root of all evil, as I haven’t really encountered problems with them and find them very simple to use and maintain, but that isn’t the point of this post.

The point is that just starting a new job I figured a good thing to do was first run the unit tests to make sure I had set up the app properly. I was treated to many failures and investigated why. I found many failures caused by a polluted database. Previous tests weren’t cleaning up after themselves, so later tests had bad state (duplicate records and that sort of thing). While that may be a plug for database level enforcement of that kind of rule, that task was beyond the scope of what I was doing.

I scoured Google looking for answers, and a day later I finally found it. Just to stretch you along even further, here’s what it wasn’t:

  • shoulda not running implicit teardowns
  • transactional fixtures being turned off

No, it was a great deal dumber than that, and a thanks to Eric Artzt, whoever you are, for providing the solution. The table that was giving me fits is a MyISAM table, which doesn’t support transactions. Which means there are no rollbacks to clean up my DB state. Which means I either have to explicitly put calls to do that into an explicity-defined teardown method or switch the engine on the table in question.

Apple never ceases to amaze me

April 30th, 2009

I can’t actually post screenshots, because it’s a work project again.  I got some html documents from our graphic designer, and I wanted to incorporate them into our code base.  Wanting to just get at the html code, I figure a simple text editor would do that for me.  I used Apple’s cra… amazing text editor TextEdit, foolishly thinking that like notepad or writepad on Windows I would see, you know, the text of that file.

This idiotic Apple piece of software tried interpreting the html document and rendering it as would a web browser.  I don’t see any mode switcher which would allow me to actually see the html either.

With absolutely 0 toolbars or the like for editing the content in a WYSIWYG manner, I’m dumbfounded.  How could that possibly be the best way to open this document?  If I used Dreamweaver, I could understand, because Dreamweave actually supports graphical development of html documents.  But it also has a simple and easy-to-find mode switcher to let me go back and forth.  And in that case, I still find the visual designer useless.

“Text”Edit has 0 graphical support that I can see (because Apple things are supposed to “just work” and be “intuitive,” I feel fine setting the bar that high) and no visible way of switching to “text edit” mode.

1 more example of Apple not living up to the hype surrounding.  In the 1 year+ I’ve been using the Mac platform I have been so underwhelmed.  It is every bit as frustrating as Windows, just in different areas.  If you like Apple’s stuff and can get work done with it, great.  Continue to do so.

The actual hardware is prettier though.  It’s nice that the Eye on the laptop’s lid lets everyone know how creative and unique I am.