|
What we're listening to:
|
amend git commitFebruary 4th, 2009Thanks to the beauty of local git repositories, I no longer worry about committing. So what if things aren’t pretty, its just a snapshot of my work in progress. When I push to remote, however, its a good idea to clean up these commits. Up till now I’ve been using git rebase -i which, while very handy, can be a bit of overkill for my normal workflow. Instead I can use git commit --amend to squash my new changes into the latest commit. This is what I’ve usually been doing with rebase -i anyways. And making a new git alias removes the extra typing. Git ‘R done validate image dimensions with paperclipJanuary 31st, 2009I’m liking paperclip, in a recent project I chose it specifically because it buffers writes on uploads, which should help keep memory usage down. I needed to validate that an uploaded image was at least a certian size, and it was a little tricky, but here’s what I came up with:
has_attached_file :image,
:styles => { :original => ["1000x600>", :jpg]},
:whiny_thumbnails => true
def validate
dimensions = Paperclip::Geometry.from_file(self.image.queued_for_write[:original])
self.errors.add(:image, "Please upload a file at least 700 pixels wide") if dimensions.width < 700
self.errors.add(:image, "Please upload a file at least 200 pixels tall") if dimensions.height < 200
end
like it? hate it? have something better? redmine and gitJanuary 15th, 2009Over the last few months, I’ve become a big fan of Redmine. It’s just what I was looking for when I was tired of setting up a TRAC for each project but missed the source code integration when we were using Basecamp. Redmine doesn’t look very pretty at first, but there’s some good themes (we use the basecamp inspired theme) that make it much better. When we started using git, it brought some new issues up with our workflow and redmine, and we’re not the only ones . Some people are just changing and making the repository on their redmine server their “central” repository, but our redmine is hosted locally, and our repositories for each project are hosted on the deployment machine. This causes some problems because the redmine repo doesn’t receive updates. There’s a plugin aimed at solving this, but it’s not functional yet. We solved it with a quick hack to run a git pull before redmine brings in new information from the repository:
Index: app/models/repository/git.rb
===================================================================
--- app/models/repository/git.rb (revision 2251)
+++ app/models/repository/git.rb (working copy)
@@ -36,6 +36,7 @@
end
def fetch_changesets
+ scm.fetch
scm_info = scm.info
if scm_info
# latest revision found in database
Index: lib/redmine/scm/adapters/git_adapter.rb
===================================================================
--- lib/redmine/scm/adapters/git_adapter.rb (revision 2251)
+++ lib/redmine/scm/adapters/git_adapter.rb (working copy)
@@ -24,6 +24,11 @@
# Git executable name
GIT_BIN = "git"
+
+ def fetch
+ cmd="#{GIT_BIN} --git-dir #{target('')} --bare fetch"
+ shellout(cmd)
+ end
# Get the revision of a particuliar file
def get_rev (rev,path)
Simple, but functional. Give us a shout if this helps you or if you have a better solution. rspec+rcov = segfault deathNovember 14th, 2008I was pounding my head against the keyboard. Rspec with rcov was crashing whenever it felt like it. I was getting all kinds of errors like: /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/matchers/be.rb:92: [BUG] rb_gc_mark(): unknown data type 0×0(0×489ffc8) non object ruby 1.8.6 (2007-09-24) [i686-darwin9.3.0] opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/example/example_group_methods.rb:344: [BUG] Segmentation fault ruby 1.8.6 (2007-09-24) [i686-darwin9.3.0] not to mention a bus error or two as well. Then I found this article with this solution: $ gem sources -a http://gems.github.com (you only have to do this once) $ sudo gem install mergulhao-rcov from this guy. Then the world was right again. giving backOctober 17th, 2008Recently I had a need to implement an on-demand payment model with a payment processor (Cybersource). I use the Active Merchant plugin for transaction operations almost exclusively, and nobody had added support for Cybersource subscriptions or on demand payments. So I implemented it myself over the last couple days, and published the code on github . Currently it supports creating subscriptions, updating subscriptions (which is also how you cancel), and preforming a purchase (auth+capture) via subscription. I’m willing to implement other things like credits, straight auths and captures if there’s a community need. There’s not much in the way of docs yet (like most of Active Merchant), but it’s working for me. I’d also be willing to write a post on using the features I added, just drop a not in the comments if you would like to see that. I’ll be submitting a patch soon, and hopefully this will get pulled into the official ActiveMerchant repository. This is the first real open source contribution we’ve made at ELEVATION (most things we need we find are already done), and it feels good to give back. You should try it. getting gitOctober 15th, 2008I’ve been hesitant to explore git since subversion was (I thought) really handling all my needs just fine. Why waste time learning another version control workflow? Over time, I started to realize there were things about git that would be really nice, like nice branching and merging in particular, but I thought, that’s for some day when I have time to learn it, or my pain becomes too great with branches (which I don’t use that often in svn). Just a couple days ago I needed to extend some code that was hosted on github, so I forked it, cloned it, and just started to work. In that process I’m discovering things that are just making git start to click. Whoops, didn’t mean to commit that yet: git-reset. I need to pull in some other changes, but can’t yet because I have uncommitted changes: git-stash. Combined with the git bundle for textmate, I’m actually having fun learning git. Moral: Try new stuff (in a real-life scenario), it’s fun and can make your life better. OpenSource Court RulingAugust 15th, 2008The U.S. Court of Appeals for the Federal Circuit ruled that licenses used for OpenSource projects can be enforceable under copyright law. Here are some excerpts from the summary document published by the Court:
Copyright holders who engage in open source licensing have the right to control the This decision is important because it reduces the legal uncertainty regarding OpenSource rights and will make it a more attractive option for software development and OpenSource distribution models. Elevation continues to support the OpenSource ideology. Litigation about OpenSource is rare Active Record Race ConditionsAugust 7th, 2008Today, I got bit by ActiveRecord race condition related to validates_uniqueness_of. Sometimes I just blindly trust that Rails is going to take care of things, and so it surprised me when I ended up with duplicate records in my database. A few people have written about this, and apparently it’s in the API Docs now, but I just hadn’t thought about it before. The solution looks to be enforcing unique constraints at the database level. Timestamps in join table causing readonly recordsJuly 31st, 2008By default I include the rails t.timestamps in my create table migrations. Always nice to know when a model has been created or updated, right? And what could it hurt? Well, when they are in a join table for a habtm relationship they cause the associated records to be marked as readonly. This is because rails can’t save those extra timestamp attributes. If timestamps or any other extra join information is needed, then use a join model instead with has_many :through. exception_notifier gotchaJuly 22nd, 2008Yesterday I was investigating why exception_notifier wasn’t, well, notifying me of exceptions. I checked out the log, and I was getting an error like this: ActionView::TemplateError (protected method `filter_parameters' called for #<Admin::ProductsController:0x2aaaaeccd6b0>) Turns out Rails 2.1 breaks the version of exception notifier you get by running script/plugin install exception_notifier. To get the correct version, you have to run script/plugin install git://github.com/rails/exception_notification.git Pretty lame, they really should update that. |