Accepting changes from a remote Git repository

Posted about 2 hours back at Barking Iguana

Previously I wrote about how to work on an external project using Git. I didn't show how the owner could accept your changes though.

Connect to the remote repository

Being a committer to the project you of course already have the repository cloned. If you don't, now might be a good time to do that.

The person that's asked you to review their changes should have provided you with the repository location, and probably a branch with the changes that they'd like you to look at. Add the remote repository to yours.

git remote add \
  craigwebster http://barkingiguana.com/~craig/project_name.git

Double check just to make sure the repository is correct.

git remote show craigwebster
  * remote craigwebster
    URL: http://barkingiguana.com/~craig/smqueue.git/
    New remote branches (next fetch will store in remotes/craigwebster)
      dev/documentation master

Grab the information on those juicy looking branches

git fetch craigwebster

Review, critique, rinse, repeat

To look at the changes you'll want to check them out to a local branch. Ask Git to track the remote branch for you so that any changes the patcher makes can easily be pulled into this branch.

git co --track \
  -b craigwebster-sprozzled-gromits-are-good \
  craigwebster-sprozzled-some-gromits

Do your stuff, run the test suite, look over the code, discuss it with your peers, whatever.

git whatchanged
commit b9e0f1b4ff4bc196513c9551f6c25f0ee40d991f
Author: Craig R Webster <craig@xeriom.net>
Date:   Wed Nov 19 20:53:08 2008 +0000
# and so on

I'll assume that you accept the changes wholesale - you'll have to cherry pick commits if you don't.

Ask for a wider review

In some cases it may be appropriate to ask for a wider review of the changes before they are accepted into the master branch. Maybe the change is too huge to be in a minor release, or maybe it's patching a development branch. In these cases you can apply the changes to a branch.

git checkout dev/version-2-0-45
git merge craigwebster-sprozzled-some-gromits
git commit -m \
  "The Gromits are well and truly Sprozzled." \
  --author "Craig R Webster <craig@xeriom.net>"
git push origin \
  dev/version-2-0-45:refs/heads/dev/version-2-0-45

From here you can merge, commit, or otherwise screw around with the commit much as you would with any change you've made.

Accepting the changes without review

If the change is appropriate to merge directly into the master branch then you can do that too.

git checkout master
git merge craigwebster-sprozzled-some-gromits
git commit -m \
  "The Gromits are well and truly Sprozzled." \
  --author Craig R Webster <craig@xeriom.net>"
git push origin master

GitHub Uses Tender

Posted about 2 hours back at entp hoth blog - Home

If you read Ruby blogs, you probably know that GitHub is run and built by some of the best programmers Ruby has. So we're pretty stoked to get an endorsement like this.

Working on other people's projects with Git

Posted about 2 hours back at Barking Iguana

I'm still somewhat new to Git. I'm not really sure what best practice is, or what protocol surrounds providing patches to other people's projects. Here's the best I could come up with for making a change to someone's project and allowing them to incorporate the changes if they desire them.

Clone the repository

First off you'll need to get a copy of the project to work on. Hopefully they're using Git... because I've not worked out the best way to handle if they're not.

git clone git://github.com/username/project_name.git
cd project_name.git

Add a public repository

If you're like me then you're disconnected a lot of the time. I setup a public Git repository that I could make code available from by pushing changes to it. If you're connected all the time (or at least all the time that another developer might want to get to your code) then you probably don't need to do this.

cd git remote add public ssh://barkingiguana.com/~craig/code/project_name.git
git push public master

Time to work

Here comes the hard but interesting bit: do some work. Typically this involves checking out a branch for a feature, bug fix or topic area.

git checkout -b sprozzle-the-gromits
# ... do the work ...
git add gromits/blue.txt
git commit -m "Sprozzle Gromit with the blue face."

# ... do more work ...
git add gromits/cherry.txt
git commit -m "Cherry Gromits are even better with more Sprozzle."

Conflict resolution

While you've been working on your awesome patch (and until your patch is accepted back into the project origin) there may be upstream changes. You'll want to make sure that it applies cleanly to the master branch as this will increase the chances that your patch will be accepted.

git checkout master
git pull origin master
git checkout sprozzle-the-gromits
git rebase master
# resolve any conflicts
git commit -m "Made branch patch master at 351ac1b cleanly."
git push public

Advertise your changes

You want to make just the changes on the branch available to the public so push the branch to the public repository. Once again, this is only needed if you live a disconnected life.

git push public sprozzle-the gromits:refs/heads/sprozzled-gromits

And relax...

Your changes are now available to the public. They can clone your repository and fetch any of your pushed branches. Now would be a good time to email the owner of the project and ask nicely that they pull from your repository and check out the changes you've made.

If you need to make more changes to the branch, do the work on the branch, commit it, and do a git push public from the branch (or a git push public sprozzle-the-gromits from a different branch).

Difference is the spice of life

The project you want to work on may not support this style of contributing. Check with the project team before embarking on your quest.

Deferring Tests with Test::Unit in Rails

Posted about 3 hours back at almost effortless

Now that we have that nice syntax for tests in Rails, I'm happy just using the baked-in Test::Unit stuff. Well... maybe I still need Mocha. But the other stuff like RSpec, test/spec, and Shoulda? Meh. The only thing missing from Test::Unit is an easy way to defer tests. That's important. I'd been dropping "flunk" in tests to note that they weren't implemented yet, but that can get confusing pretty quickly.

Luckily, there's a quick and easy way to add "deferred" tests. Here's how:

 
# test/test_helper.rb
class Test::Unit::TestCase
 
  def defer
    puts "\nDeferred: #{caller[0]}"
  end
 
end
 
# test/functional/home_controller_test.rb
require 'test_helper'
 
class HomeControllerTest < ActionController::TestCase
  test "should defer test" do
    defer
  end
end
 

This would produce output like so...

~/git/h8ter $ autotest
loading autotest/rails
/opt/local/bin/ruby -I.:lib:test -rtest/unit -e "%w[test/functional/home_controller_test.rb...
Loaded suite -e
Started
....................
Deferred: ./test/functional/home_controller_test.rb:6:in `test_should_defer_test'
............................................
Finished in 0.795139 seconds.

64 tests, 123 assertions, 0 failures, 0 errors

I thought I'd seen a commit from Koz that added a nice way to defer tests in Rails, but I can't seem to find it. Please post a comment if you know what I'm talking about. In the meantime, here we are with a quick and dirty solution for your enjoyment.

jQuery on Rails: Why Bother?

Posted about 3 hours back at RailsTips.org - Home

In which I explain why I use jQuery at times and how you can as well. Oh, and I provide a wealth of links. Links are fun!

A few people have suggested that I post about how to use jQuery with Rails. I thought about it and felt that others have already covered it quite well but why not collect their posts here for you to enjoy, right? Plus, I do all my JavaScript from scatch so I do not really ever use the helpers Rails provides and as such could not post intelligently on them.

So John, When Did You Quit Prototype?

I haven’t! I do not intend to ever quit using Prototype. Honestly, I have used jQuery quite a bit less than Prototype. I have found that jQuery and Prototype are both great and in different situations I will use a different library. The one thing I will say is even if you don’t actually switch to jQuery, I think it is important to learn new things and stretch yourself. It is good to feel frustrated and like a beginner. Also, jQuery takes a very different approach which has actually helped me write better Prototype code. Hope this is helpful and not overwhelming. :)

Creating A Plugin

Addicted to New jQueryToday, I wrote an article on How to Create a jQuery Plugin From Scratch over on my Addicted To New site. I picked out the most basic thing a plugin could do and explained each step in a lot of detail. Give it a read if you are into Prototype but are curious about jQuery.

Live Search and Fancy Zooming

Ordered List jQueryAfter creating my live search with quicksilver for prototype example, I decided to port it to jQuery (view demo). Then, humbly, I was corrected by the jQuery man himself, John Resig, who re-ported my port in a more jQuery-ish functional style. For those that are curious, I also massaged the AJAX-RDoc project to use quicksilver searching. This is really helpful when you can’t quite remember a method name.

Likewise, when I created fancy zoom for prototype, my partner in crime, Steve Smith, created a port of fancy zoom for jQuery (view demo). Fancy Zoom is great for showing text and images with an Apple-esque, in page zoom transition or even Flash if you have a video you would like to feature.

jQuery Railscast

RailsCasts jQueryRyan Bates did an awesome job showing how to use the jQuery on Rails plugin with Rails in a recent screencast. He also gave a really quick example on how to create a plugin. I would recommend watching this and subscribing to his Railscasts, which are great.

jRails Plugin

RailsCasts jQueryjRails is a drop-in jQuery replacement for Prototype/script.aculo.us on Rails. Using jRails, you can get all of the same default Rails helpers for javascript functionality using the lighter jQuery library. Ryan shows how to use it in the screencast mentioned above, but I thought I would also mention it separately. If you are a fan of the Rails javascript/ajax helpers, this plugin is for you. It makes each of them work with jQuery and has some nice demos on the site.

Link Love

While dispelling the myth that Rails is tied to Prototype, DHH gave some jQuery examples.

Brandon showed how he includes the authenticity token using prototype and the pug automatic shows how to do the same using jQuery.

Ben Curtis has a tutorial on how to do drag and drop sorting with jQuery and Rails.

Yehuda Katz has a year old presentation on jQuery and Rails that is still worth a look.

Nutrun has a more full post on how to do unobtrusive ajax with jQuery and Rails

ErrTheBlog (errtheblog is dead. long live errtheblog!) gave jQuery some serious love a while back in their jSkinny article. Chris also created a plugin named Facebox that is used extensively on GitHub and has a short post that shows how to get jQuery working with respond_to.

If you are a fan of Low Pro, Dan Webb has created a port of Low Pro for jQuery. (article #1, article #2)

In some Rails Rumble observations, it was noted that jQuery was more widely used than Prototype.

Don’t forget that “jQuery UI provides abstractions for low-level interaction and high-level, themeable widgets, built on top of the jQuery JavaScript Library, that you can use to build highly interactive web applications.” Be sure to check out the demos.

If you are a fan of Twitter, you can follow jQuery for links to articles and such.

Nathan Smith gave a crash course on jQuery that includes a sweet airline seat demo.

jQuery does not come with all of Prototype’s functionality out of the box, but you can usually find a plugin that does what you need if you are too lazy to make something yourself.

Lastly, one of my favorite jQuery resources is Visual jQuery. I found this site a blessing when I was trying to learn jQuery.

Feel free to post your favorite jQuery/Rails resources as a comment below.

A Modest Proposal

Posted about 4 hours back at A Fresh Cup


There has been an astounding amount of invective and discussion over a recent addition to Rails. Briefly, if you have an array in Rails, you can now use ordinal numbers to get at the first ten members through aliases such as Array#second, Array#third, and so on. Some people are concerned about code bloat, some are concerned about lack of elegance, and DHH’s judgment in writing this bit of code has been seriously challenged.

Well, I’m not happy either - because the changes don’t go far enough. Let’s add one more method to Array and be done with it:


Class Array
  def by_ordinal(pos)
    self[pos.to_i]
  end
end

With this simple addition, you can refer to Array.by_ordinal("3rd"), Array.by_ordinal("21st"), or even Array.by_ordinal("407th"). As a bonus, the naming of the individual members is consistent with Rails’ Inflector#ordinalize method. Please join me in pushing for this to be included in Rails core.

      

JBoss on Rails: Deploying Rails Apps to a JBoss App Server

Posted about 4 hours back at Rails Inside

slide1001-300x225.jpg

Java-heads will be familiar with JBoss, a popular Java EE-based application server. Bob McWhirter has been working on a plugin to make it easy to deploy Rails applications to a JBoss app server - something that could be quite appealing if you work in a Java-only zone (common in managed deployment situations) or if you want to sell your code to enterprises with this restriction.

Bob's deployer is called, simply, jboss-rails (Github repository) and it deploys Rails applications to JBoss AS 5.x servers using JRuby and JRuby-Rack. He's also written several blog posts about it. JBoss on Rails gives an overview of actually deploying an app, JBoR: Will it cluster? looks at the clustering situation, and there are instructions for installing and using jboss-rails. There are also some slides from a presentation he recently gave at Raleigh RubyCamp.

Rails has already been easily deployable in Java-land by using Glassfish, but it's nice to see another option available.

Introducing RubyFu

Posted about 4 hours back at Jim Neath

RubyFu is a project I’ve been working on, along with Phil Jeffs, for a couple of weeks now. We’ve got big plans so keep your eyes peeled.

What is RubyFu?

RubyFu is a community driven ruby news site. Users can submit their news stories, comment on other stories and vote. If a news story receives a vote total of less than a certain number, then post is removed. Say bye-bye spam.

At the moment, RubyFu is pretty simple but we have a lot of ideas floating around, so soon it will be more awesome than anything. ever.

So if you’ve got a post, a tutorial or anything else that you find interesting, come and share it was us at RubyFu.

New Edge Rails Feature: Default Scoping

Posted about 4 hours back at Rails Inside

In his "What's New in Edge Rails" series, Ryan Daigle has just written about "default scoping." You're probably familiar with regular named scopes on Rails models, but now there's a default_scope method that defines a scope that exists by default on find methods.

Example:

class Article < ActiveRecord::Base
  default_scope :order => 'created_at DESC'
end

The default scope also carries across, by default, to any regular named scopes that you might have, so if you want to override the default scope, you have to force it.

Do note, however, that this feature is currently only in edge rails.

HappyMapper: Easy XML / Object Mapping for Rubyists

Posted about 5 hours back at Ruby Inside

happy-xml.jpg HappyMapper is John Nunemaker's attempt at "making XML fun again" for Rubyists by providing an object to XML mapping library with a succinct syntax. Essentially, you can use HappyMapper to rapidly turn XML into Ruby objects - even nesting them inside and referring to each other. This is powerful stuff. To install, just gem install happymapper

John's own examples are powerful demonstrations of how it works, so check them out. The first is parsing the XML returned from Twitter. The statues and associated users in that XML can be processed (with the relationship maintained) with the following code:

class User
  include HappyMapper

  element :id, Integer
  element :name, String
  element :screen_name, String
  element :location, String
  element :description, String
  element :profile_image_url, String
  element :url, String
  element :protected, Boolean
  element :followers_count, Integer
end

class Status
  include HappyMapper

  element :id, Integer
  element :text, String
  element :created_at, Time
  element :source, String
  element :truncated, Boolean
  element :in_reply_to_status_id, Integer
  element :in_reply_to_user_id, Integer
  element :favorited, Boolean
  has_one :user, User
end

statuses = Status.parse(xml_string)
statuses.each do |status|
  puts status.user.name, status.user.screen_name, status.text, status.source, ''
end

Installing Rails on Hardy Heron (Desktop)

Posted about 8 hours back at O'Reilly Ruby

There are way too many operating systems and choices within those operating systems to provide a straightforward explanation of installing Rails. To solve that, I'm creating screencasts that show how to install Rails, demonstrating both how to do it and that it actually is possible.

Installing Rails on Ubuntu Hardy Heron (Server)

Posted about 8 hours back at O'Reilly Ruby

Want to install a Rails development environment on a bare-bones Ubuntu server setup? It's not that hard.

Things We Have Found

Posted about 8 hours back at cameronyule.com

In collaboration with Mister, I’m happy to announce the launch of Things We Have Found, a place for us to share our reactions and insights to living in Glasgow via photography.

While it’s just the two of us getting things rolling, we hope to grow the site by adding fellow contributors from around the world to create a collective visual journal of the interesting and bizarre.

Installing Rails on Ubuntu Hardy Heron (Server)

Posted about 9 hours back at O'Reilly Ruby

Want to install a Rails development environment on a bare-bones Ubuntu server setup? It's not that hard.

Installing Rails on Hardy Heron (Desktop)

Posted about 9 hours back at O'Reilly Ruby

There are way too many operating systems and choices within those operating systems to provide a straightforward explanation of installing Rails. To solve that, I'm creating screencasts that show how to install Rails, demonstrating both how to do it and that it actually is possible.


1 2 3 ... 575