Let it be…yikes

September 29th, 2009

Rails/ActiveRecord::Base acts_as_obfuscated – hide your object ids

September 27th, 2009

I’ve always liked the idea of obfuscating the ids of my ActiveRecord::Base objects when using them in url. There’s lots of ways to go about this and through past projects I’ve used various mechanisms to accomplish it. Sometimes it’s nice and others it’s required. You might want to hide the number of users/objects/whatevers you have in you system or make it harder for malicious users to gain access to resources by guessing urls.

Well regardless of the reason(s) I’ve created a simple plugin/mixin, acts_as_obfuscated, that does exactly this with a single line of code. An example is in order:

class User < ActiveRecord::Base
  acts_as_obfuscated

  ...
end

and that's it.

$ ./script/console
Loading development environment (Rails 2.3.4)
>> u = User.create(:name => 'Bob')
=> #
>> u.id
=> 4
>> u.eid
=> "diBGnp"
>> User.find(u.id)
=> #
>> User.find(u.eid)
=> #
>>

The piece that's not shown above is an implementation of to_param.

def to_param
    self.eid
end

The effect of this is that anywhere you provider a user object in an 'id => user' param you get the self.eid rather than the default to_param of self.id. So a url that would look like http://mysite.com/users/4 would become http://mysite.com/users/diBGnp.

=link_to(user.name, :controller => 'users', :action => 'show', :id => user)

<a href="http://mysite.com/users/diBGnp">Bob</a>

acts_as_obfuscated doesn't get int the way of custom to_param functions so long as the first portion is the acts_as_obfuscated to_param function:

class User < ActiveRecord::Base
  acts_as_obfuscated

  def to_param
    CGI.escape("#{super.to_param}-#{self.name}").gsub(/\./, '_')
  end
end

$ ./script/console
Loading development environment (Rails 2.3.4)
u= U>> u= User.last
=> #
>> u.to_param
=> "diBGnp-Bob"
>> User.find(u.to_param)
=> #

That will allow you to have seo/ad placement friendly urls without exposing your internal object identifiers.

Anyway, check it out, use it, let me know what you think. The code can be found on github: http://github.com/ross/acts_as_obfuscated.

It can be installed as a plugin by running the command:

./script/plugin install git://github.com/ross/acts_as_obfuscated.git

If you want to see it in action check out: ClBrow - A Visual way to Shop Craigslist, which is a bit slower than I'd like to do the load on my dreamhost db, but hopefully I'll get around to fixing that soon...

-rm

Armadillo Aerospace – Rocket Tug-O-War

September 13th, 2009

Some context… What do you think NASA would do if it wanted to test the effects of wind gusts on one of its rockets? How much do you think they’d spend designing, planning, and testing the test system? For better or worse this is why space will ultimately be concurred not by government programs, but by private enterprises (granted for the a lot of the private endeavors are being funded by NASA and friends.)

“We wanted to get a feel for how the vehicle would react to sudden changes in wind speeds as it moved upward. The only thing we could think of to induce a similar force was to attach a really long cable to one of the legs and have someone pull on it during a hover.”

via Armadillo Aerospace – News Archive.

YouTube Preview Image

(original video)

Won’t need no breakfast, I’ll be gone!

September 3rd, 2009
YouTube Preview Image

Better dead than fed, PETA says

August 16th, 2009

The Center for Consumer Freedom, which represents the food industry, a frequent target of PETA campaigns, released data filed by PETA with the state of Virginia that shows PETA has killed more than 10,000 animals from 1998 to 2003. “In 2003, PETA euthanized over 85 percent of the animals it took in,” said a press release from the lobby, “finding adoptive homes for just 14 percent. By comparison, the Norfolk (Va.) SPCA found adoptive homes for 73 percent of its animals and Virginia Beach SPCA adopted out 66 percent.”

via Better dead than fed, PETA says.

An old article, but still interesting. While there may be explanitions, including PETA taking animals they feel are being inhumanely euthanized so that they can be put down in an acceptable manner, but the differences are still pretty stark.

US cities may have to be bulldozed in order to survive – Telegraph

June 19th, 2009

‘Dozens of US cities may have entire neighbourhoods bulldozed as part of drastic “shrink to survive” proposals being considered by the Obama administration to tackle economic decline.’

via US cities may have to be bulldozed in order to survive – Telegraph.

see also this /. post

Pretty interesting story about how vast potions of formerly prime land within cities are being razed in order to return them to nature and reduce the drain on government (and related) serivces. Having been to Detroit (only for a short weekend) I was amazed at how run down and empty large portions of the area/city seemed to be. Its understandable how downsizing it looked at as a failure, it’s just not a part of progress as we’ve come to know it. However, in the case of many rust-belt cities we’ve already “lost” they are ghosts of their former prosperous selves and the only way to move forward is to shrink them down to a manageable size.

SET Energy » US bike sales higher than car sales in 2009

May 27th, 2009

“During the first quarter of 2009, more bicycles were sold in the US than cars and trucks. While the Great Recession is hurting bike sales, they didn’t fall as fast as automobiles. Around 2.6 million bicycle purchases were made, compared to ~2.5 million cars and trucks that left our nation’s lots.”

via SET Energy » Blog Archive » US bike sales higher than car sales in 2009.

Pretty cool, though it would be interesting to know what percentage of the bikes sold are being used as a mode of transportation, not just for kids/playing.

The Associated Press: Obama changes office name, pushes Web work

May 12th, 2009

“Coupled with that, Obama read a 33-page report with comments from his pre-presidency Web site, letting him know his supporters’ single top priority for the new administration: changing the nation’s policy banning marijuana.”

via The Associated Press: Obama changes office name, pushes Web work.

You have to wonder how seriously Obama will take that request. I have a hard time imagining he’d would take action on it given that I’ve never heard him publically speak about it, but who knows. It’s pretty interesting that it was the most frequently mentioned request/comment. Also interesting that pot supporting people feel free enough to speak up on the record in favor of legalization. I’d imagine at least part of the reason it is the number one request is internet demographics, people who are internet savvy and motivated enough to visit Obama’s pre-election site happen to coincide with the pro-pot segment. At least I have a hard time seeing the greater population careing one way or another.

The Associated Press: EPA: ethanol crops displaces climate-friendly ones

May 5th, 2009

WASHINGTON (AP) — The Environmental Protection Agency says that corn ethanol — as made today — has a worse impact on climate than gasoline when land use changes are considered.

via The Associated Press: EPA: ethanol crops displaces climate-friendly ones.

A prediction about Obama

April 29th, 2009

I’m going to go out on a limb and make a rather bold prediction. That not only will Obama be reelected, but there will be a decently strong movement for the lifting of the term limit when his 2nd term is coming to a close. I say this as I sit here watching his 100 day news conference. I’m as impressed with him and his answers now as I was when I watched him speak in 2004. I’m not sure that policy-wise he’s that special, but I think as a person and leader there’s something here that is. Something that I haven’t seen before and can only hope we see again.