Author Archive
Sunday, April 25th, 2010
I’ve been working with Rails and Ruby since 2006 and I’m surprised I hadn’t put this together for myself:
$ cd test # from your rails app root
$ ruby unit/a_model_test.rb
As compared to:
$ ruby -I"lib:test" "/usr/local/Cellar/ruby-enterprise-edition/1.8.7-20090928/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/a_model_test.rb"
Definitely a hand to forehead moment when I read that! Found it in a comment here:
https://rails.lighthouseapp.com/projects/16213/tickets/8
*Assumes your ruby command is set up correctly in your shell’s environment, of course.
Posted in open source, ruby, ruby on rails | No Comments »
Tuesday, March 16th, 2010
I’ve moved from MacPorts to Homebrew which includes a recipe for installing MongoDB. After installing Homebrew, just run this as your normal user:
brew install mongodb
If you prefer to store your MongoDB data all under your home directory, you might find Mislav’s gist suits your needs instead:
http://gist.github.com/265272
If you prefer installing from source, check out this post:
http://shiftcommathree.com/articles/how-to-install-mongodb-on-os-x
Enjoy.
Posted in Homebrew, MongoDB, kete development, open source, ruby, ruby on rails, sysadmin | No Comments »
Saturday, January 24th, 2009
Here’s a quick one. Say you are debugging a bit of code in a plugin that doesn’t fall under the Rails app you are working on’s ActiveSupport context and thus “logger.debug” is not available to you.
You could write up your own logging mechanism, with or without using the Logger gem. However, if what you are working on is run by the Rails app and thus has the apps global constants available, you could simply tie it into the existing logger object in the Rails app like so in your file:
logger = RAILS_DEFAULT_LOGGER
Then you can use logger.debug, logger.info, etc. to your heart’s content. One caveat, if you are working on a gem or a something more general that won’t necessarily always be run in the context of Rails, then you will want to pull your use of logger out before distributing your code. Otherwise you add a dependency on Rails that you may not intend.
Posted in open source, random, ruby on rails | No Comments »
Thursday, January 15th, 2009
You have to give Logical Awesome credit for how much work they do to integrate GitHub’s services with tools that developers use.
The Gist service is a good example. First they added command line support for it, then they simultaneously added in-editor support in Textmate, vim, and my own personal favorite emacs. The blog post announcing gist support in emacs and vim is here.
So how do you add the gist support to emacs?
First, you’ll need an account on github.com and have set up your ~/.gitconfig as outlined in here.
Then download or clone the gist.el file from http://github.com/defunkt/gist.el, copy only the gist.el file from that repository to someplace in your emacs load path (in my case /Users/walter/Library/Preferences/Aquamacs Emacs/ because I use Aquamacs on a Mac), and add a line to your ~/.emacs file or in my case /Users/walter/Library/Preferences/Aquamacs Emacs/Preferences.el that looks like this:
(require ‘gist)
Then you have to either restart your emacs program or do M-x load-library and answer prompt with gist for the new gist commands to be available.
Now you have M-x commands like these:
- gist-view-gist
- view gists after they’re posted
- gist-region
- Post the current region as a new paste at gist.github.com
Copies the URL into the kill ring.
- gist-region-private
- Post the current region as a new private paste at gist.github.com
Copies the URL into the kill ring.
- gist-buffer
- Post the current buffer as a new paste at gist.github.com.
Copies the URL into the kill ring.
- gist-buffer-private
- Post the current buffer as a new private paste at gist.github.com.
Copies the URL into the kill ring.
- gist-region-or-buffer
- Post either the current region, or if mark is not set, the current buffer as a new paste at gist.github.com
Copies the URL into the kill ring.
- gist-region-or-buffer-private
- you can probably guess…
- gist-fetch
- Given an gist id, fetches a Gist and inserts it into a new buffer
If the Gist already exists in a buffer, switches to it.
Very useful stuff for collaboration, but without leaving your editor.
Enjoy,
Walter
Posted in open source, random, ruby on rails | No Comments »
Tuesday, September 9th, 2008
A natural inclination when one starts programming in Ruby is to use “and” and “or” instead of the “&&” and “||” to increase readability. However, “and” is not a drop in syntactic synonym with “&&” and the same goes for “or”.
James pointed out a good blog post that explains the issues around order of precedence with these operators:
http://blog.jayfields.com/2007/08/ruby-operator-precedence-of-and-which.html
It’s worth reading the comments.
It should also be noted that the Ruby on Rails source style guide has a preference for “&&” and “||”:
http://rails.lighthouseapp.com/projects/8994/source-style
Posted in kete development, open source, ruby on rails | No Comments »
Friday, August 29th, 2008
I just had to resolve my first conflict in git. It’s a little more convoluted than with subversion, but slicker overall.
So you run into a conflict during a merge (implied by this git pull command):
$ git pull kete_master master
…
Auto-merged app/helpers/application_helper.rb
Auto-merged app/views/layouts/application.rhtml
CONFLICT (content): Merge conflict in app/views/layouts/application.rhtml
…
Automatic merge failed; fix conflicts and then commit the result.
First up, you need to have your git config point at opendiff on Mac OS X. Do the following if you haven’t already (you only have to do this once and it will be set permanently):
git config –global merge.tool opendiff
Then from the shell run this:
$ git mergetool
And then you should see output something like this:
Merging the files: app/views/layouts/application.rhtml
Normal merge conflict for ‘app/views/layouts/application.rhtml’:
{local}: modified
{remote}: modified
Hit return to start merge resolution tool (opendiff):
Hit return and the OpenDiff application should startup with the conflicted file. It will have side by side comparisons of local version of the file and the remote version of the file with nifty highlighted areas where things are different. Select the first highlighted region, go down to the bottom right and choose the appropriate side in the “Action” menu, then proceed on to the next one, and so on until you have taken care of all differences. Then click File > Save Merge.
Back on the shell you are ready to do commit your resolved file. Do “git commit” and you enter an editor to put in your commit message.
Move on to other tasks, you’re done.
Posted in random | No Comments »
Tuesday, July 29th, 2008
I was trying to install a gem on a client’s machine that I had previously been able to grab successfully, but it failed like this:
$ sudo gem install some_gem
Updating metadata for 475 gems from http://gems.rubyforge.org/
…
complete
ERROR: could not find some_gem locally or in a repository
I thought perhaps rubyforge was unavailable, so I repeated the command. Still no luck. I did a web search and found a possible answer:
$ gem sources -a http://gems.github.com/ # adds metadata for the gems hosted by github
That actually didn’t do it either. Including github’s gems slowed things down when doing a gem install, so I decided to remove it from the sources list:
$ gem sources -r http://gems.github.com/ # drops github’s gems metadata
So I tried a “gem help sources” and discovered that I could clear the local cache like so:
$ sudo gem sources -c
*** Removed user source cache ***
*** Removed latest user source cache ***
*** Removed system source cache ***
*** Removed latest system source cache ***
Then I tried the gem install again:
$ sudo gem install some_gem
Bulk updating Gem source index for: http://gems.rubyforge.org/
Successfully installed some_gem
1 gem installed
Installing ri documentation for some_gem
Installing RDoc documentation for some_gem
Success! Hope this helps someone else.
Posted in random | No Comments »
Monday, January 14th, 2008
This is handy for reading (or cutting and pasting from) documentation that is in HTML that is included with open source software without jumping to an external browser. Check it out:
http://bc.tech.coop/blog/080110.html
Posted in html/css, kete development, open source | No Comments »
Sunday, October 14th, 2007
The other day I was asked how much disk space a particular Kete project’s production database used. I didn’t have an answer, so I started searching for one.
In my case, the db software is MySQL and getting a report about various aspects of a db’s tables boils down to this query:
show table status;
The output of this query has way more information than I need, plus to get the total number of bytes used you have to add all the values up anyway, so I decided to make a rake task to make this repeatable and return something succinct.
I have added the new rake task to the Kete app’s codebase. If you aren’t a Kete user, but need this functionality for your Ruby on Rails app, you can find it here:
http://svn.kete.net.nz/projects/kete/trunk/lib/tasks/db-disk-usage-report.rake
Note there is a formatting method taken from the Rails Helpers, I would love to not duplicate this definition. If anyone has a recommendation for the best way to pull this method into this rake task, I would appreciate it. Probably a simple include statement, but I didn’t get around to figuring out the correct incantation.
I would also love to hear how best to make this handle other database software, for example PostgreSQL, too.
Cheers,
Walter
Posted in kete development, open source, random, ruby on rails, sysadmin | 1 Comment »
Sunday, October 14th, 2007
As previously mentioned, I have written a guide on how to set up Kete (also applicable to other Rails apps though Kete includes some extra required software and niceties to make it easier) for Development on Mac OS X. This guide also includes best practices for Deployment. So the following guide can be seen as the first half of the story:
http://kete.net.nz/documentation/topics/show/16-creating-a-kete-development-environment-on-mac-os-x
But what about the host that you are deploying to? I cover that for Debian Etch in the following guide:
http://kete.net.nz/documentation/topics/show/15-preparing-a-debian-etch-host-to-be-deployed-to-for-kete
You might also be curious what software Kete requires. Here’s a breakdown:
http://kete.net.nz/documentation/topics/show/19-technical-requirements
Cheers,
Walter
Posted in kete development, open source, random, ruby on rails, sysadmin | No Comments »
|