Thanks Akismet!

Posted over 7 years back at zerosum dirt(nap) - Home

I’m probably a bit behind the game on this one, but huge props are due to Akismet for making my blog life just a bit more pleasant. Before it was installed last week, I was deleting hoards of comment spam every day. Today, none.

In other blog-related news, I’m still planning on moving productions over to Mephisto, but have been hard pressed for time lately. Fortunately (when I get around to it), it has Akismet support baked right in.

UPDATE: finally moved over to a new blogging platform! About time, eh?

Episode 47: Two Many-to-Many

Posted over 7 years back at Railscasts

There are two different ways to set up a many-to-many association in Rails. In this episode you will see how to implement both ways along with some tips on choosing the right one for your project.

Hardware Accelerated Flash Video - the turning point?

Posted over 7 years back at work.rowanhick.com

I'm looking forward to the web 2.bomb era to be over. Every man and his dog is building yet another social networking, api enabled, ajaxified, beta tag wearing application and waiting for the VC money to flow in. Just follow techcrunch.com and yawn every morning at the yasu* of the day. Outside of the VC crazed crowd some interesting things are happening. Adobe's announcement on HD content deployed using the Flash Player is very interesting indeed, not so much from the feature set, but what it's actually doing technically. We now have a cross platform web delivered piece of code that is utilizing the GPU. I think this has been lost on a few people. I'm personally not interested in the HD aspect, what I am interested in is the hardware acceleration. If an appropriate DirectX or OpenGL piece of hardware is present it then the flash player will utilise it to enable full screen 'HD' video. Very very impressive. Tinic is a genius. This marks (in my mind) a turning point for web apps - the crack in the dam has started, finally we are starting to really break out of the limitations of the browser, and will pave the way for some serious development of serious web applications. Perhaps Flash will have the last laugh.. I am not a fan boy of any tech religion. I do not think Adobe are God, Microsoft know it all, or Rails will fulfill my every desire. However in unison it seems, people are looking for the (r)evolution - the race is currently on to see who can deliver this technology we're crying out for. Taking the real (engineering) enterprise to the web Back for one of the companies I worked for, we had a huge Delphi application that is a fat client, fat server model. A CAD/CAM app, it required lots of CPU cycles to render an entire window (real .. not the microsoft kind) structure, apply business rules etc, compared to your atypical order processing system (which are just fancy crud operations). Currently on the web, all you see are these crud applications. The so called web 2.0 era, for all of the applications we see, are really just crud systems. So nothing is there to support anything other than crud. Which rules out doing this particular app. The browser in it's next version is only just starting to see a Canvas object whereas this has been the backbone of many desktop applications for years/decades! Flash/Flex/Air notwithstanding of course... What gets me excited, is when the potential for an application like the previously mentioned CAD/CAM system to be delivered over the web, utilising the advantages of the web AND the advantages of the desktop. The only way of doing that is breaking out of the web browser sandbox to use a desktop's horsepower. I think this hardware acceleration development might just kick off a chain reaction. Imagine via Actionscript, suddenly being able to harness the GPU's drawing system.... or even processing for horribly complex calculations that suit for parallelism - instead of bringing your system to a crawl, pipe them off to your GPU. Think of the possibilities.... An interior design application, rendered in beautiful photo realism with all the lighting effects you could imagine, allowing you to design your dream interior and order everything for it online. Games, delivered online, using local client connections for rendering - all code, etc retained on the server and piped down on demand. Infinitely expansive as the code is never kept locally. Log back in the next day and all new baddies added into the game without you even knowing until you stumble upon one. User powered grid computing services. Imagine firing up your beast of a computer, connecting to medical research system, and donating your GPU cycles - without having to download any nasty java or activex applets to your desktop. Companies are salivating over the PS3's power for this and scrambling to figure out how to do it, imagine taking this to the desktop arena ? Is this not the Holy Grail we want ? Let's start imagining, dreaming up the possibilities... and if we're smart enough, try to realise them. My mind's already going a hundred miles an hour. What would you build if you had access to the best of both worlds ?! *yasu - Yet Another (......y) Start-Up

Roundtable: Women in Development II - Ruby on Rails Podcast

Posted over 7 years back at Ruby on Rails Podcast

Part II of a discussion with and about women in development.
See also:

Gentoo: Dependency info is missing!

Posted over 7 years back at benmyles.com - Home

After a clean Gentoo minimal install and emerge of a Ruby on Rails stack, Gentoo started throwing the following error when managing services via inet.d:


* Dependency info is missing! Please run
* # /sbin/depscan.sh
* to fix this.


Running /sbin/depscan.sh seemed to have no effect.

I tracked down a post from a mailing list that explains what's going on.

In a nutshell, my /var/lib/init.d/deptree file was empty. I'm still not sure why. The /sbin/depscan.sh command rebuilds this file, but not if it's newer than some configuration file in /etc. The answer is to rm /var/lib/init.d/deptree and then run /sbin/depscan.sh.

If you get any errors about /bin/mktemp not existing, make sure to emerge mktemp.

Easy solution, but quite obscure!

Episode 46: Catch-all Route

Posted over 7 years back at Railscasts

Sometimes you need to add complex/dynamic routes. This is often impossible to do in routes.rb, but do not worry. It can be accomplished with a catch-all route. See how in this episode.

Tumbleranting

Posted over 7 years back at zerosum dirt(nap) - Home

Seth Godin is a nicer guy than I am (he’s probably better dressed, too): I would have ballparked his quote a little higher. Explanation: there’s a “don’t waste my time” fee.

As a freelancer, this happens to me all the time and it’s muy frustrating. I like hearing ideas, I like helping you structure your approach, I love developing solutions, applications, tools for you. I don’t even mind giving estimates and free advice. But in order to do that, you need to tell me what it is you want.

And no, “just like digg but with/for xxx” isn’t what I’m talking about :-).

Code Digest #1

Posted over 7 years back at Revolution On Rails

When you program for a living, you write lots of code. There is often some code that you are fond of. We start the Code Digest series to present such code written by the RHG developers. We encourage other teams and individual developers to share similar snippets in their blogs so we all can learn from each other and become better rails developers.

Daniel Silva



<%= link_to(image_tag("/images/icon.gif", :style=>"padding-right:0px;"), {:controller => '/registration', :action => 'login', :dest => request.request_uri}, {:style => ""}) %> 

With this line, I can create an image link using Rails code, to take advantage of the power of routes in Rails while still creating this kind of structure: <a href="#"><img border="0"/></a>



Jack Dempsey



Ok, so here's something useful for using keyboard short cuts to navigate through a small supporting application:
def include_keyboard_shortcuts

hotkey = 'Ctrl+Shift'
code_string = ''
keys = {
'm'=>'/account_info/show',
's'=>'/account_info/index',
'c'=>'/menu/go?menu_action=new_customer',
'p'=>'/products',
'o'=>'/account_info/orders',
't'=>'/order_tracker',
'x'=>'/auth_sessions/destroy',
'r'=>'/current_users/reset_password'
}

current_user_needed = %w{m o r}

keys.each_pair do |k,v|
next if current_user_needed.include?(k) && current_user.nil?
code_string << "shortcut('#{hotkey}+hm#{k}',function() { document.location.href='#{v}' });\n"
end

javascript_tag(code_string)

end



Then in a layout file just:
<%= javascript_include_tag 'shortcuts' %>
<%= include_keyboard_shortcuts %>



Makes use of a nice shortcuts.js lib.


Val Aleksenko


This is a fragment of a conversation on our internal IRC with my solution for refactoring a piece of code:
May 07 14:07:56 <Anthro> There has to be a better way to do this (x and y are non-negative integers): increment = (x!=0) ? ( (y!=0) ? 0 : 1 ) : -1
May 07 14:08:22 <Anthro> I think it can be done with math instead of logic.
May 07 14:16:56 <jack> Anthro: have you thought about using sin and cos? ;-)
May 07 14:18:42 <muzzy> (x <=> 0) <=> (y <=> 0)



Granted, it is not as clear as the original, but it is hard to resist it from the aesthetic point of view.

Val Aleksenko


I love writing dynamically generated methods and classes in Ruby as the next guy. When I was writing acts_as_readonlyable, I needed to manage multiple connections. I found that the easiest solution for managing active connections was generation of an AR class for each read-only definition and borrowing the connection from it. The usage is acts_as_readonlyable :read_only_entry_in_database_config.
def acts_as_readonlyable(readonly_db)
define_readonly_class(readonly_db) unless ActiveRecord.const_defined?(readonly_class_name(readonly_db))
end

def readonly_class_name(db)
"Generated#{ db.camelize }"
end

def define_readonly_class(db)
ActiveRecord.module_eval %Q!
class #{ readonly_class_name(db) } < Base
self.abstract_class = true
establish_connection configurations[RAILS_ENV]['#{ db }']
end
!

end



Warren Konkel


The ConfigFile class is a quick and easy way to load YAML files located in your Rails application's config directory. Simply place a YAML file into your config directory and then access it like a hash. For example this will read your config/database.yml: ConfigFile['database']['production']['adapter'].
class ConfigFile
def self.[](arg)
@@cached_configs ||= {}
@@cached_config_mtimes ||= {}

base_name = "config/#{arg}.yml"
filename = File.join(RAILS_ROOT, base_name)
raise "ERROR: Config not found: #{base_name}" unless File.exists?(base_name)

if @@cached_configs[arg].nil? || @@cached_config_mtimes[arg] < File.stat(filename).mtime.to_i
@@cached_configs[arg] = YAML.load(File.open(filename))
@@cached_config_mtimes[arg] = File.stat(filename).mtime.to_i
end

@@cached_configs[arg]
end
end

Code Digest #1

Posted over 7 years back at Revolution On Rails

When you program for a living, you write lots of code. There is often some code that you are fond of. We start the Code Digest series to present such code written by the RHG developers. We encourage other teams and individual developers to share similar snippets in their blogs so we all can learn from each other and become better rails developers.

Daniel Silva



<%= link_to(image_tag("/images/icon.gif", :style=>"padding-right:0px;"), {:controller => '/registration', :action => 'login', :dest => request.request_uri}, {:style => ""}) %> 

With this line, I can create an image link using Rails code, to take advantage of the power of routes in Rails while still creating this kind of structure: <a href="#"><img border="0"/></a>



Jack Dempsey



Ok, so here's something useful for using keyboard short cuts to navigate through a small supporting application:
def include_keyboard_shortcuts

hotkey = 'Ctrl+Shift'
code_string = ''
keys = {
'm'=>'/account_info/show',
's'=>'/account_info/index',
'c'=>'/menu/go?menu_action=new_customer',
'p'=>'/products',
'o'=>'/account_info/orders',
't'=>'/order_tracker',
'x'=>'/auth_sessions/destroy',
'r'=>'/current_users/reset_password'
}

current_user_needed = %w{m o r}

keys.each_pair do |k,v|
next if current_user_needed.include?(k) && current_user.nil?
code_string << "shortcut('#{hotkey}+hm#{k}',function() { document.location.href='#{v}' });\n"
end

javascript_tag(code_string)

end



Then in a layout file just:
<%= javascript_include_tag 'shortcuts' %>
<%= include_keyboard_shortcuts %>



Makes use of a nice shortcuts.js lib.


Val Aleksenko


This is a fragment of a conversation on our internal IRC with my solution for refactoring a piece of code:
May 07 14:07:56 <Anthro> There has to be a better way to do this (x and y are non-negative integers): increment = (x!=0) ? ( (y!=0) ? 0 : 1 ) : -1
May 07 14:08:22 <Anthro> I think it can be done with math instead of logic.
May 07 14:16:56 <jack> Anthro: have you thought about using sin and cos? ;-)
May 07 14:18:42 <muzzy> (x <=> 0) <=> (y <=> 0)



Granted, it is not as clear as the original, but it is hard to resist it from the aesthetic point of view.

Val Aleksenko


I love writing dynamically generated methods and classes in Ruby as the next guy. When I was writing acts_as_readonlyable, I needed to manage multiple connections. I found that the easiest solution for managing active connections was generation of an AR class for each read-only definition and borrowing the connection from it. The usage is acts_as_readonlyable :read_only_entry_in_database_config.
def acts_as_readonlyable(readonly_db)
define_readonly_class(readonly_db) unless ActiveRecord.const_defined?(readonly_class_name(readonly_db))
end

def readonly_class_name(db)
"Generated#{ db.camelize }"
end

def define_readonly_class(db)
ActiveRecord.module_eval %Q!
class #{ readonly_class_name(db) } < Base
self.abstract_class = true
establish_connection configurations[RAILS_ENV]['#{ db }']
end
!

end



Warren Konkel


The ConfigFile class is a quick and easy way to load YAML files located in your Rails application's config directory. Simply place a YAML file into your config directory and then access it like a hash. For example this will read your config/database.yml: ConfigFile['database']['production']['adapter'].
class ConfigFile
def self.[](arg)
@@cached_configs ||= {}
@@cached_config_mtimes ||= {}

base_name = "config/#{arg}.yml"
filename = File.join(RAILS_ROOT, base_name)
raise "ERROR: Config not found: #{base_name}" unless File.exists?(base_name)

if @@cached_configs[arg].nil? || @@cached_config_mtimes[arg] < File.stat(filename).mtime.to_i
@@cached_configs[arg] = YAML.load(File.open(filename))
@@cached_config_mtimes[arg] = File.stat(filename).mtime.to_i
end

@@cached_configs[arg]
end
end

Ticketish

Posted over 7 years back at benmyles.com - Home

It has been a while since I've posted on my personal blog. In fact, I've decided to start fresh. Lately I've been very busy at Integral Impressions working on some great Ruby on Rails projects.

One such project is Ticketish. Just a few days ago we started sending out invitations for a private beta program. Ticketish is a simple issue/bug/ticket management web app, designed to do what it needs to do and then get out of the way.

We built Ticketish for internal use, and have been using it for some months now. We've come to really appreciate it, and decided to add some polish and release it to the world. If you're interested, go sign up for the beta and I'll get an invitation to you within a day or two (probably quicker).

The State (And Future) Of The UJS Plugin

Posted over 7 years back at danwebb.net - Home

Over the past few weeks loads of people have been asking me about what’s going on the UJS plugin. It’s obviously fallen in to disrepair so people, understandably, have been concerned. There has been a reason for this aside from the fact that I am a lazy barsteward (which of course I am, but that’s beside the point). Here is a letter I’ve just written to the UJS mailing list that I’d thought I’d post here to try to get a little more feedback. It’s a little bit long but bear with me…

I’ve been chatting to Luke and users of UJS about what to do with it and still haven’t quiet decided hence the lack of news but below is a rundown of where we are at on the whole thing. However, this is definitely personal opinion and doesn’t necessarily represent Luke’s opinion on the matter.

Essentially, the status is that, of late, I personally have not used UJS at all and have found a much better process by using Low Pro on its own without all the Ruby scaffolding of the UJS plugin. Secondarily, after talking to lots of developers at RailsConf it seems that the UJS plugin has failed to truly achieve it’s main goal which is to get Rails developers to write JavaScript using progressive enhancement. Many people seem to mainly use the plugin to get their JavaScript in to a separate file which is actually not even essential to progressive enhancement and I think this is a failing in the design of UJS itself. To achieve progressive enhancement you really need to think of JavaScript as a separate layer on top of a working HTML application but UJS lets you get away with keeping behavior in your views and hence leads many developers to think in the same way as they did before but think they are unobtrusive because they don’t see any JavaScript in their HTML – which is obviously not what we wanted to achieve. While many people can and do successfully use UJS for progressive enhancement even more seem not to – UJS has not been the ‘angel on your shoulder’ that I originally wanted it to be.

On top of this, the method by which the generated JavaScript is kept in the session has many limitations which myself and Luke have been aware of from the start. It’s not generally a good idea to keep this much information in the session (in fact, normally I never store more than a user ID if I can help it) and while acceptable for light to medium use it does have an upper limit depending on the type of session storage you are using. Rails edge now uses cookies to store session info by default which have a very very low limit which will cripple UJS completely. We have considered other alternatives such as some kind of file based storage but every time it just strikes me as too much scaffolding just to allow developers to put behavior in their view files which, as a said above, I’ve come to believe is a really bad idea anyway.

One of the things that I do personally like and something that has received the most positive feedback are the behavior helpers (the make_*) stuff which essentially encapsulate common tasks with sensible defaults in a very Rails like way. It’s a real time saver and the conventions provided mean that the best path (such as using this.href for the Ajax url) is the easiest. Recently, I’ve come to do this in my own projects via Low Pro and it’s behavior ‘classes’ (although they need a better name!). Now via Low Pro I can write stuff like:

Event.addBehavior({
  '.product a.description' : Remote.Link({ update : 'product_description' }),
  '.product' : Draggable({ revert : true }),
  '#basket' : Droppable
});

I really like this and am slowly building up a library (which you can see if you look at the Low Pro trunk) of common behaviors. There’s a date picker, a drag/drop implementation and the remote stuff I’ve illustrated above. I’m planning on writing autocompleters and in-place editors as behaviors as well. But behaviors have proven really easy to write and I love them as a tool for building site specific components. In fact, as I’ve worked with Low Pro it’s become apparent to me that behaviors are by far the killer feature which is interesting as they were just an experiment I hacked together one day without much thought.

So what to do? Well, there’s two ways to go as far as I can see. The first is to shut down development on UJS completely (or hand it over to another party if anyone is interested) and go on to promote the techniques of implementing progressive enhancement using Low Pro that I’ve found to be so successful recently. This could possibly be via the UJS4Rails site or through my own site – I’m not sure which would be a better platform right now.

The other would be to re-think the UJS plugin totally and go for some kind of 2.0 release that would take a completely different tack. However, all of the ideas for this I’ve thought of or heard so far don’t really compel me to write them. I think to work on this myself I’d need to be sure that I’d want to use it and so far this is not the case but any ideas and feedback are very welcome so please do drop me a mail or feedback on this list.

Either way, we need to make fixes to the current plugin to make it work with Rails 1.2.3 which I’ve been working on recently but I’d love patches if you’ve already solved these issues yourself (which it appears many of you have).

So yes, that’s it. Let me know what you think, I’d appreciate any feedback you have.

Large Mephisto Deployment

Posted over 7 years back at Mephisto - Home

I’m not sure how many other large sites use Mephisto, but I managed to deploy it to the-leaky-cauldron.org the other day (after lots of heavy modding to get things like polls and article ratings working). Leaky gets about 3 million unique visitors a month – and with 9,000 articles and over 300,000 comments (not all of which have converted yet) I thought I’d let you know. —Mephisto group message by Nick Poulden.

I’m not sure, but I think that’s one of the largest Mephisto installations around. Great job, Nick Poulden!

New DRYML getting closer

Posted over 7 years back at The Hobo Blog

If you’re wondering why things have been a bit quiet around here of late, it’s because we’ve been taking a pretty hard look at where we’ve got so far with DRYML, and figuring out where exactly we want to be.

We really wanted to raise our game and make DRYML even simpler and more elegant than it is already. The good news is, things are starting to come into focus.

During this process we’ve considered a lot of out-there ideas, and have even considered a complete re-write with an entirely new approach. Fortunately, and as so often seems to be the case, the journey has taken us full circle, and we’ve ended up pretty close to where DRYML is right now. It’s just we now have a much better understanding of why it works so well :-). All we really need is a bit of polish here and there and a couple of tweaks.

Just today James and I have had a great day nailing all this down, and it looks like we’re ready to start implementing the new features. We’re really excited about this new stuff and are really looking forward to getting it ready for you all to start hacking with.

I’m afraid your existing DRYML pages won’t work with the new syntax, but the overall semantics is hardly changed so it should be a no-brainer to port everything over. It will be well worth it!

New DRYML getting closer

Posted over 7 years back at The Hobo Blog

If you’re wondering why things have been a bit quiet around here of late, it’s because we’ve been taking a pretty hard look at where we’ve got so far with DRYML, and figuring out where exactly we want to be.

We really wanted to raise our game and make DRYML even simpler and more elegant than it is already. The good news is, things are starting to come into focus.

During this process we’ve considered a lot of out-there ideas, and have even considered a complete re-write with an entirely new approach. Fortunately, and as so often seems to be the case, the journey has taken us full circle, and we’ve ended up pretty close to where DRYML is right now. It’s just we now have a much better understanding of why it works so well :-). All we really need is a bit of polish here and there and a couple of tweaks.

Just today James and I have had a great day nailing all this down, and it looks like we’re ready to start implementing the new features. We’re really excited about this new stuff and are really looking forward to getting it ready for you all to start hacking with.

I’m afraid your existing DRYML pages won’t work with the new syntax, but the overall semantics is hardly changed so it should be a no-brainer to port everything over. It will be well worth it!

Episode 45: RJS Tips

Posted over 7 years back at Railscasts

This episode is packed with little RJS goodies. Learn the different ways to access an element, how to add "if" conditions and how to apply an effect to multiple elements.