Accidental Resolution


August 13th, 2007

On any sizeable Rails app you are bound to define a method in a controller that you don’t intend on making routable and neglect to call hide_method or making. A really good sign that a method shouldn’t be routable is when the method has arity. I wrote this small script to find all of the action_methods that also accept arguments. Read on for the script.

Some day I will probably collect this and other code healthiness introspections into a rails plugin providing handy rake targets such as “rake show:actions_with_arity”. For now, load it with script/runner or inside of a script/console session.


    def get_all_controllers
      controllers=[];
      ObjectSpace.each_object do |obj|
        if (obj.is_a? Class)&&(obj.name=~/Controller$/)
          controllers << obj
        end
      end
      controllers
    end

    def get_controllers_actions_methods
      controllers = get_all_controllers

      controllers_actions= controllers.inject([]){ |controllers_actions,controller|
        if controller.respond_to?(:action_methods)
          controller_actions_methods = controller.action_methods.to_a.map { |act|
            controllers_actions << controller.new.method(act)
          }
        end
        controllers_actions
      }
      controllers_actions
    end

    def output_methods
      ms = get_controllers_actions_methods
      y (ms.reject{|x|x.arity==0}.map(&:inspect).sort)
    end

Another scribble


June 1st, 2007

With the addition of control-point-free curves my scribble code can be a lot more concise and rapid. Here is a little ditty that draws spirals with a degree of randomness

Scribble!


May 14th, 2007

I have been playing a lot with a project that is intended to be a cross platform port of NodeBox. I even hope to contribute significantly to the project where I can. Other than that, I love graphics and programming so I am just going to play with it, report and fix bugs, and share my nifty hacks. I title this one: the curvy cubist

GFDL Presentation Videos


May 10th, 2007

There is a video of my May 5 presentation on Ruby on Rails at the Chiglug meeting.

There are a lot of other great presentations there, too!

Evolving Drawing Gone Underground


May 7th, 2007

Evolving Drawing is now by invitation only. You can still watch it evolve but now it is out of beta and into superproductionseriousnessenterprise mode. Watch your inbox!

A tiny taste of my rails presentation


May 3rd, 2007

I lovingly hand-wrote the slides in SVG using present. I will be giving the talk at 3pm on the IIT campus in the Cleversafe office for the CHIGLUG meeting

Mindsplatter: a camping app


April 30th, 2007

This evening my first little camping app was born. It was a hard 16hr labor full of FastCGI related complications. My dreamhost account is exhausted. He’s just a little guy with no database, so try not to slam him too hard with traffic. Little, yet he is already big enough to wear the handmedown pantsuit of my old bloxsom weblahh I had so many years ago. In no time flat I will have stitched that pantsuit up with a few shiny sequins.

Present: An SVG slideshow script


April 16th, 2007

So in the process of writing a small presentation on Ruby on Rails for my local GNU/Linux Group I wrote an SVG slideshow program. OO Impress was just too frustrating with it’s utter lack of support for Fluxbox. The script is right here in my subversion repository. It is going to improve substantially as I use it to write a few more presentations I need to write for work. The sample slides.yml is a draft of the presentation I was actually working on.

My New Love: fields_for


March 21st, 2007

So I have always loved form_for, but it becomes tricky to use when your object is more complex than a simple flat object with attributes that can be set in the manner. But what if you are trying to save a model that has assoctiated models? Enter fields_for


class Package < ActiveRecord::Base
   has_one :address
end

class Address <ActiveRecord::Base
end

<% form_for @package do |f| %>
  <%= f.text_field 'special_notes' %>
  <% f.fields_for @package.address do |a| %>
    <%= a.text_field 'first_line' %>
    <%= a.text_field 'second_line' %>
  <% end %>
<% end %>

This title intentionally left blank.


March 19th, 2007


>> def foo; puts "bar"; end
=> nil
>> p = :foo.to_proc
=> #<Proc:0xb7bbad20@/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/core_ext/symbol.rb:10>
>> p = :foo.to_proc
=> #<Proc:0xb7bbad20@/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/core_ext/symbol.rb:10>
>> eval(p.to_ruby).call
NameError: undefined local variable or method `obj' for #<Object:0xb7d359fc>
        from (eval):2
        from (irb):28:in `call'
        from (irb):28
        from :0
>> p.to_ruby
=> "proc { |*args|\n  obj.send(self, *args)\n}" 

Javascript: It Just Sunk In


February 22nd, 2007

So recently I just realized how it all works. Functions are first class data types in javascript and thus you can create JSON hashes out of them which is what creates the CamelCaseObject.method() like syntax. That took a looong time to sink in.

Evolving Drawing


February 21st, 2007

So there is a little app I wrote recently: evolving drawing. I can’t say too much about it without spoiling. Check it out, it is at a half baked state but I am still in talks with my “customer” to improve it. It runs using rails, a lot of XMLBuilder, cutting edge prototype and SVG. It only works in firefox as far as I know. Feel free to see the source in my svn. The code is all mine but the idea is completely that of my friend Joe Philips.

Allison Mephisto Template


January 5th, 2007

This is the initial release of Allison Mephisto (v0.1). You can see it in action, um, right on this page here. It is a great way to theme your rdocs just like your project’s blog. In fact, if you customize allison’s styles to your project you can use the exact same css with my theme, with just a little bit of finagling for the rounded corners. To install it just run svn co http://ternimal.com/svn/allison/trunk allison from the RAILS_ROOT/themes/site-1 directory. If you have any problems just shoot me an email or leave a comment.

Cissaby is CSS as ruby


January 4th, 2007

Check out my latest exploit, cissaby: a way to do CSS in ruby. Right now it isn’t quite finished, but I have figured out how I can make it work. So let’s say I have some CSS code like this:


div.article{ font-color: red; }
#errors, #header{ padding: 0px; }
#errors{ display: none; }
#header h2{ font-size: 2em; }
In cissaby I would have done it like this:

Cissaby::Builder.new{
  div.article{ :"font-color" => "red" }
  errors!/header!{ :padding => "0px" }
  errors!{:display => "none"}
  header!._.h2{ :"font-size" => "2em"}
}

Pretty uselessly awesome, huh? svn co http://ternimal.com/svn/cissaby/trunk/

Using ./script/runner


December 30th, 2006

Stop abusing the console!

Here is my confession: I’ve used the console in production mode to do some heavy lifting. I was shaking with nervousness though, because one weird typo or mixed up paste buffer could have meant disaster. You don’t have to though: In rails there is a pretty amazing tool, runner, that I only recently discovered the usefulness of.

Generally, it is a tool that lets you execute code within your rails app’s environment. For me, specifically, it helps me avoid abusing the console. Which is a hard habit for CLI-junkie like me to avoid. But I’m a programmer, damnit, I write programs. And I’m also not a DBA, I don’t trust myself to shoot from the hip with SQL. See, sometimes at work our beta-testing server’s database gets rebuilt. No biggie, but it is annoying because a few user settings that are in the database get lost. Until now I had been fixing this by tooling in the console. It is repepitive, it is tedious, and I typically forget how I have gone through the process by the time I finish it. Now I just write up my complex alterations in vim and run them with runner


  #!/usr/bin/env script/runner
  User.find_by_name($1).roles << Role.find_by_name('Super User')

And here is a little tip that you will help you debug your scripts: wrap everything in a transaction, then throw a breakpoint at the end of the transation so you can find out if your code did what you intended it to. Or, here is an even better tip, use breakpoint’s assert method.