ThreadsafeBenchmark

Posted almost 7 years back at Revolution On Rails

When testing products such as services which need to be stress-tested prior to release, it's necessary to use multi-threading to get as close to real world usage as possible. This gem, though not intended to be a replacement for full-fledged testing suites such as LoadRunner, can provide instantaneous results to facilitate TDD programming. To reduce the duplication of code, the gem utilizes Ruby's built-in Benchmark module for the base functionality while preventing the output from clobbering through the use of thread-specific IO buffers.

require 'threadsafe_benchmark'
include ThreadsafeBenchmark

threads = []
max_num = 5000

5.to_i.times { |i|
threads << Thread.new(max_num) { |n|
threadsafe_bm(6) { |x|
x.report("for:") { for i in 1..n; a = "1"; end }
x.report("times:") { n.times do ; a = "1"; end }
x.report("upto:") { 1.upto(n) do ; a = "1"; end }
}
}
}

threads.each { |t| t.join }

Using the standard Benchmark, the results would be printed haphazardly making it difficult to read and interpret. But ThreadsafeBenchmark cleans everything up giving us nicely laid out columns.

usersystemtotalreal
for0.000000.000000.000000( 0.002889)
times0.000000.000000.000000( 0.002477)
upto0.000000.000000.000000( 0.002479)
for0.000000.000000.000000( 0.002401)
times0.010000.000000.010000( 0.002586)
upto0.000000.000000.000000( 0.002413)
for0.000000.000000.000000( 0.002205)
times0.010000.000000.010000( 0.002245)
upto0.000000.000000.000000( 0.002272)
for0.000000.000000.000000( 0.001822)
times0.010000.000000.010000( 0.001958)
upto0.000000.000000.000000( 0.001943)
for0.010000.000000.010000( 0.010090)
times0.010000.000000.010000( 0.009225)
upto0.010000.000000.010000( 0.007986)

The gem and source files are available at Rubyforge.

ThreadsafeBenchmark

Posted almost 7 years back at Revolution On Rails

When testing products such as services which need to be stress-tested prior to release, it's necessary to use multi-threading to get as close to real world usage as possible. This gem, though not intended to be a replacement for full-fledged testing suites such as LoadRunner, can provide instantaneous results to facilitate TDD programming. To reduce the duplication of code, the gem utilizes Ruby's built-in Benchmark module for the base functionality while preventing the output from clobbering through the use of thread-specific IO buffers.

require 'threadsafe_benchmark'
include ThreadsafeBenchmark

threads = []
max_num = 5000

5.to_i.times { |i|
threads << Thread.new(max_num) { |n|
threadsafe_bm(6) { |x|
x.report("for:") { for i in 1..n; a = "1"; end }
x.report("times:") { n.times do ; a = "1"; end }
x.report("upto:") { 1.upto(n) do ; a = "1"; end }
}
}
}

threads.each { |t| t.join }

Using the standard Benchmark, the results would be printed haphazardly making it difficult to read and interpret. But ThreadsafeBenchmark cleans everything up giving us nicely laid out columns.

usersystemtotalreal
for0.000000.000000.000000( 0.002889)
times0.000000.000000.000000( 0.002477)
upto0.000000.000000.000000( 0.002479)
for0.000000.000000.000000( 0.002401)
times0.010000.000000.010000( 0.002586)
upto0.000000.000000.000000( 0.002413)
for0.000000.000000.000000( 0.002205)
times0.010000.000000.010000( 0.002245)
upto0.000000.000000.000000( 0.002272)
for0.000000.000000.000000( 0.001822)
times0.010000.000000.010000( 0.001958)
upto0.000000.000000.000000( 0.001943)
for0.010000.000000.010000( 0.010090)
times0.010000.000000.010000( 0.009225)
upto0.010000.000000.010000( 0.007986)

The gem and source files are available at Rubyforge.

Word Loop (#149)

Posted almost 7 years back at Ruby Quiz

Here's a fun little challenge from the Educational Computing Organization of Ontario.

Given a single word as input try to find a repeated letter inside of it such that you can loop the text around and reuse that letter. For example:

$ ruby word_loop.rb Mississippi
i
p
p
Mis
ss
si

or:

$ ruby word_loop.rb Markham
Ma
ar
hk

or:

$ ruby word_loop.rb yummy
yu
mm

If a loop cannot be made, your code can just print an error message:

$ ruby word_loop.rb Dana
No loop.

NetBeans: Helpful Plugins

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

So, NetBeans 6.0 Final was released a few weeks ago. v6.0 is all about the Ruby love, right out of the box. If you haven’t tried it, I implore you to give it a shot. Even if you’re not a fan of traditional “heavyweight” IDEs, I think you’ll be impressed with what they’ve done. There’s even a slimmed-down Ruby-only version. But sometimes, I must admit, I still miss the power and (relative) simplicity of vim.

I’m in the process of re-reading The Pragmatic Programmer, and was just pawing through the passage on “power editing”, in which Dave and Andy suggest that you “choose [one] editor, know it thoroughly, and use it for all editing tasks”. For me, that editor is most definitely vim. I’ve used it for quite some time, it’s familiar, I don’t even have to think about the keybindings when I’m working in vi, and I’m spoilt by the easy text manipulations that just aren’t possible with some fancy graphical editing tools. I use vim for practically everything text-related.

Everything, that is, except writing Java and Ruby code (and a few random tasks that have to be performed in a word processor, sadly). Yep, you read that right. I use vim for sysadmin tasks, hacking quick scripts, editing config files, and even taking notes, but lately I haven’t been using it where I’d probably see the single largest productivity boost from it.

Since switching to NetBeans, my comfort level with having all the tools I need in one place has increased dramatically, including things such as easy access to a console, in-IDE debugging, test output, solid class introspection, integrated rdocs, and so on. But I also realize that I’ve been doing myself a bit of a disservice when in “heavy edit” mode. Fortunately, that’s easily fixed, as there’s a vi plugin for NetBeans. YES. No idea why I didn’t bother to search for something like this before.

So in any case, if you’re interested, you can retrieve the NetBeans plugin from the jVi homepage. The file named nbvi-FOR-NB-RC1-1.1.2.×6 is the one you want (as of this writing, anyway). Once you’ve downloaded the package, you can install it in NetBeans by going to tools => plugins. Choose the downloads tab, click ‘add plugins’, select the vim core and keybindings plugins, install them, and be happy. Thanks guys, this is so awesome.

Oh and speaking of plugins, here are a few other helpful Ruby-related plugins for NetBeans that you may be interested in. Most of them are available through the plugins browser built into the IDE.

  • Rspec Support (nice!)
  • Ruby dark pastels color scheme (hrmm looks familiar…)
  • HAML and SASS plugin (if that’s the way you roll)
  • Extra Source Code Hints

Low Pro 0.5: Now Compatible With Prototype 1.6

Posted almost 7 years back at danwebb.net - Home

Today I tagged Low Pro 0.5 for release which now works with Prototype 1.6. There are a number of things about this release that are worth mentioning aside from the compatibility. Firstly, it’s gotten a little smaller as Prototype core now includes most of the functionality Low Pro used to add (DOM Ready support, inserting using DOM nodes and a lot more). It’s also got a couple of new features so here’s a rundown:

  1. Event.onReady delegates to the new dom:loaded event: Except that as before if functions are added after the DOM is loaded they fire immediately.
  2. DOMBuilder now delegates to Prototype’s new Element: Now difference in usage here though, just less code.
  3. Low Pro’s DOM methods are now gone: Prototype core does everything you should need now.
  4. Behavior.create() works just like the new Class.create(): Yes, you can now create behavior classes that inherit from other behaviors (or indeed any other class). See the Prototype’s site for more information.
  5. New core behaviors: The Remote and Observed behaviors are now included in the core so you can now turn normal links and forms into Ajaxy links and forms even more easily.
  6. Event.addBehavior.reassignAfterAjax is now false by default: Normally, if you are relying on this behavior it’s much more efficient to move to a solution using event delegation. However, if you do want your behaviors reassigned to new content after Ajax calls then go ahead and set it back to true again. Another solution is to manually call Event.addBehavior.reload();

So that’s about it. As you can see, it’s getting smaller as Prototype fills the gaps and graduating into more of a pure behavior framework. I’d be interested in adding more core behaviors for other common tasks as well as possibly getting together some kind of behavior library. I know I’m building up a fair few and I’d love to see what everyone else is doing (in fact I’ve already seen some great stuff) so suggestions are more than welcome…as are bug reports and patches. For both of these and general assistance try the Google Group.

Grab the new version and have a play.

Low Pro 0.5: Now Compatible With Prototype 1.6

Posted almost 7 years back at danwebb.net - Home

Today I tagged Low Pro 0.5 for release which now works with Prototype 1.6. There are a number of things about this release that are worth mentioning aside from the compatibility. Firstly, it’s gotten a little smaller as Prototype core now includes most of the functionality Low Pro used to add (DOM Ready support, inserting using DOM nodes and a lot more). It’s also got a couple of new features so here’s a rundown:

  1. Event.onReady delegates to the new dom:loaded event: Except that as before if functions are added after the DOM is loaded they fire immediately.
  2. DOMBuilder now delegates to Prototype’s new Element: Now difference in usage here though, just less code.
  3. Low Pro’s DOM methods are now gone: Prototype core does everything you should need now.
  4. Behavior.create() works just like the new Class.create(): Yes, you can now create behavior classes that inherit from other behaviors (or indeed any other class). See the Prototype’s site for more information.
  5. New core behaviors: The Remote and Observed behaviors are now included in the core so you can now turn normal links and forms into Ajaxy links and forms even more easily.
  6. Event.addBehavior.reassignAfterAjax is now false by default: Normally, if you are relying on this behavior it’s much more efficient to move to a solution using event delegation. However, if you do want your behaviors reassigned to new content after Ajax calls then go ahead and set it back to true again. Another solution is to manually call Event.addBehavior.reload();

So that’s about it. As you can see, it’s getting smaller as Prototype fills the gaps and graduating into more of a pure behavior framework. I’d be interested in adding more core behaviors for other common tasks as well as possibly getting together some kind of behavior library. I know I’m building up a fair few and I’d love to see what everyone else is doing (in fact I’ve already seen some great stuff) so suggestions are more than welcome…as are bug reports and patches. For both of these and general assistance try the Google Group.

Grab the new version and have a play.

Last blog post of 2007?

Posted almost 7 years back at Mike Mondragon

Synopsis

I’ve been in a writers block for useful bits of information to post on my blog. I guess I’ll give a summary of things I’ve seen and done lately and perhaps that will inspire others.

Work

I started my own S-Corp. to work freelance out of over the summer. I was motivated to do so after attending the The Business of Rails session at RubyConf 2007. And I’ve gotten a lot of great tips on how to be a business person in Rails from the Google group Ruby on Rails meets the business world

I started consulting through Contentfree over the summer. They are a Rails consulting shop and have been working on a startup for their Eachday photo and memories sharing site. Its been great to working with Dave Myron there. Dave is one of the best coders and software designers I’ve ever worked with and I’m not saying that just to get more work!

RubyConf

I went to RubyConf 2007. It was fun. I played a lot of Werewolf (see #53) in the evenings. Sadly, it felt like the close knit party was/is over in the Ruby community since all the momentum that Rails has brought to Ruby is bringing in the masses (I’m in that group, one of “those guys”). My guess is that RailsConf 2008 is going to feel like a JavaOne, and RubyConf 2008 will feel like RailsConf 2007 with to many tracks.

#fauna

At RubyConf I got to meet the people I’ve met in the #fauna channel on irc.freenode.net. I think some of the greatest Ruby code and ideas I’ve been exposed to are from people in that channel. Shout outs to adamblock, agile, evn, lifo, heaveysixer, loincloth, defunkt, and others.

Evan Weaver

Evan is a genius and pretty cool dude.

Pratik

Pratik is a genius and is very active on RailsCore contributions. He says Just Say No To Named Spaced Models so I guess you should ignore this post: Rails Models in a Namespace

Chris Wanstrath

Chris is a genius is full of ambition Ambition Google Group

ditching Typo

I’m probably going to ditch this Typo blog when I can make time to do it. I’ll either go with an another Rails based blog called Mephisto or Evan Weaver’s Bax blog which uses scripts and Apache SSI and is hidden on fauna’s SVN on Ruby Forge: ‘svn co svn://rubyforge.org/var/svn/fauna/bax’

like Ozimodo

I’ve been thinking about doing a Camping based tumblelog. I even paid a designer to make a template for it. I’ll blog about that latter. It will be like Ozimodo and probably steel code from it.

imPOSTor

I’m sitting on a Gem called imPOSTor that will post comments to forums such as phpBB and Web Wiz Forums . I’ll probably release within the month. It has been working inside a production grade private Rails app for over a month so I think its ready to be released. “The imPOSTor library is used to automate the act of posting comments and data to forums such as phpBB and WWF. impostor encapsulates the work of posting to these forums using a common (ruby) interface.”

MMS2R

I’m about to finish the next major version of MMS2R (2.0) . I think I’ve found the best architecture for it be maintained for the long haul. Each release of MMS2R is named after a character in the Metalocalypse cartoon.

Speaking of MMS2R Luke Francl and I submitted a MMS + Rails proposal for RubyConf 2008 called “Mobile Messaging with Rails”. Luke and I are also writing a PeepCode book about Rails+MMS+Mobile phones.

Last blog post of 2007?

Posted almost 7 years back at Mike Mondragon

Synopsis

I’ve been in a writers block for useful bits of information to post on my blog. I guess I’ll give a summary of things I’ve seen and done lately and perhaps that will inspire others.

Work

I started my own S-Corp. to work freelance out of over the summer. I was motivated to do so after attending the The Business of Rails session at RubyConf 2007. And I’ve gotten a lot of great tips on how to be a business person in Rails from the Google group Ruby on Rails meets the business world

I started consulting through Contentfree over the summer. They are a Rails consulting shop and have been working on a startup for their Eachday photo and memories sharing site. Its been great to working with Dave Myron there. Dave is one of the best coders and software designers I’ve ever worked with and I’m not saying that just to get more work!

RubyConf

I went to RubyConf 2007. It was fun. I played a lot of Werewolf (see #53) in the evenings. Sadly, it felt like the close knit party was/is over in the Ruby community since all the momentum that Rails has brought to Ruby is bringing in the masses (I’m in that group, one of “those guys”). My guess is that RailsConf 2008 is going to feel like a JavaOne, and RubyConf 2008 will feel like RailsConf 2007 with to many tracks.

#fauna

At RubyConf I got to meet the people I’ve met in the #fauna channel on irc.freenode.net. I think some of the greatest Ruby code and ideas I’ve been exposed to are from people in that channel. Shout outs to adamblock, agile, evn, lifo, heaveysixer, loincloth, defunkt, and others.

Evan Weaver

Evan is a genius and pretty cool dude.

Pratik

Pratik is a genius and is very active on RailsCore contributions. He says Just Say No To Named Spaced Models so I guess you should ignore this post: Rails Models in a Namespace

Chris Wanstrath

Chris is a genius is full of ambition Ambition Google Group

ditching Typo

I’m probably going to ditch this Typo blog when I can make time to do it. I’ll either go with an another Rails based blog called Mephisto or Evan Weaver’s Bax blog which uses scripts and Apache SSI and is hidden on fauna’s SVN on Ruby Forge: ‘svn co svn://rubyforge.org/var/svn/fauna/bax’

like Ozimodo

I’ve been thinking about doing a Camping based tumblelog. I even paid a designer to make a template for it. I’ll blog about that latter. It will be like Ozimodo and probably steel code from it.

imPOSTor

I’m sitting on a Gem called imPOSTor that will post comments to forums such as phpBB and Web Wiz Forums . I’ll probably release within the month. It has been working inside a production grade private Rails app for over a month so I think its ready to be released. “The imPOSTor library is used to automate the act of posting comments and data to forums such as phpBB and WWF. impostor encapsulates the work of posting to these forums using a common (ruby) interface.”

MMS2R

I’m about to finish the next major version of MMS2R (2.0) . I think I’ve found the best architecture for it be maintained for the long haul. Each release of MMS2R is named after a character in the Metalocalypse cartoon.

Speaking of MMS2R Luke Francl and I submitted a MMS + Rails proposal for RubyConf 2008 called “Mobile Messaging with Rails”. Luke and I are also writing a PeepCode book about Rails+MMS+Mobile phones.

Advanced YAML Fixtures Gotchas

Posted almost 7 years back at Alloy Code - Home

I was very excited to use the new Advanced YAML Fixtures introduced in Rails 2.0, so I set about updating my code in an Edge Rails application I've been working on for the past year or so. There are a few caveats in using the new fixture styles, though.

The Fixtures are introspective, so if you've overridden the default name of an association in your model, you'll need to use that new name in your fixture. With the following code,

class Worker < ActiveRecord::Base
  belongs_to :status, :class_name => 'WorkerStatus', :foreign_key => 'worker_status_id'
  ...
end

The key for worker_status: should actually just be status: in the workers.yml fixture file.

The larger problem I encountered was in using a mix of IDs and fixture record names. I use a testing framework, TestRig, which was written by Mike Clark and Dave Thomas for the Pragmatic Studio. The TestRig framework takes in ID parameters of fixtures in the database, and loads them accordingly. This falls apart with the new status: full_time style of declaring relationships in fixtures, because the former relies on a 'known' ID, and the new style generates a fairly random ID instead. This leads to a bunch of broken relationships throughout the test suite.

According to the API documentation, the generated ID is constant, so I could discover that ID and use it in the TestRig calls which require an integer key, but then I've essentially lost all benefit of using the Advanced YAML Fixtures, and added some crazy complexity to my tests as well.

Advanced YAML Fixtures Gotchas

Posted almost 7 years back at Alloy Code - Home

I was very excited to use the new Advanced YAML Fixtures introduced in Rails 2.0, so I set about updating my code in an Edge Rails application I've been working on for the past year or so. There are a few caveats in using the new fixture styles, though.

The Fixtures are introspective, so if you've overridden the default name of an association in your model, you'll need to use that new name in your fixture. With the following code,

class Worker < ActiveRecord::Base
  belongs_to :status, :class_name => 'WorkerStatus', :foreign_key => 'worker_status_id'
  ...
end

The key for worker_status: should actually just be status: in the workers.yml fixture file.

The larger problem I encountered was in using a mix of IDs and fixture record names. I use a testing framework, TestRig, which was written by Mike Clark and Dave Thomas for the Pragmatic Studio. The TestRig framework takes in ID parameters of fixtures in the database, and loads them accordingly. This falls apart with the new status: full_time style of declaring relationships in fixtures, because the former relies on a 'known' ID, and the new style generates a fairly random ID instead. This leads to a bunch of broken relationships throughout the test suite.

According to the API documentation, the generated ID is constant, so I could discover that ID and use it in the TestRig calls which require an integer key, but then I've essentially lost all benefit of using the Advanced YAML Fixtures, and added some crazy complexity to my tests as well.

Engines 2.0 (ish)

Posted almost 7 years back at Rails Engines News

Hi all,

Just a quick note to let you know, should it be relevant, that we’re readied a new release of the Engines plugin, revamped and ready for Rails 2.0, and would absolutely love for you to start using it and sending feedback about what’s broken, what’s missing and what could be improved.

Grab the plugin here, check out the README, and find out more after the cut…

Continue Reading…

Advanced YAML Fixtures Gotchas

Posted almost 7 years back at Alloy Code - Home

I was very excited to use the new Advanced YAML Fixtures introduced in Rails 2.0, so I set about updating my code in an Edge Rails application I’ve been working on for the past year or so. There are a few caveats in using the new fixture styles, though.

The Fixtures are introspective, so if you’ve overridden the default name of an association in your model, you’ll need to use that new name in your fixture. With the following code,

class Worker < ActiveRecord::Base
  belongs_to :status, :class_name => 'WorkerStatus', :foreign_key => 'worker_status_id'
  ...
end

The key for worker_status: should actually just be status: in the workers.yml fixture file.

The larger problem I encountered was in using a mix of IDs and fixture record names. I use a testing framework, TestRig, which was written by Mike Clark and Dave Thomas for the Pragmatic Studio. The TestRig framework takes in ID parameters of fixtures in the database, and loads them accordingly. This falls apart with the new status: full_time style of declaring relationships in fixtures, because the former relies on a ‘known’ ID, and the new style generates a fairly random ID instead. This leads to a bunch of broken relationships throughout the test suite.

According to the API documentation, the generated ID is constant, so I could discover that ID and use it in the TestRig calls which require an integer key, but then I’ve essentially lost all benefit of using the Advanced YAML Fixtures, and added some crazy complexity to my tests as well.

Advanced YAML Fixtures Gotchas

Posted almost 7 years back at Alloy Code - Home

I was very excited to use the new Advanced YAML Fixtures introduced in Rails 2.0, so I set about updating my code in an Edge Rails application I’ve been working on for the past year or so. There are a few caveats in using the new fixture styles, though.

The Fixtures are introspective, so if you’ve overridden the default name of an association in your model, you’ll need to use that new name in your fixture. With the following code,

class Worker < ActiveRecord::Base
  belongs_to :status, :class_name => 'WorkerStatus', :foreign_key => 'worker_status_id'
  ...
end

The key for worker_status: should actually just be status: in the workers.yml fixture file.

The larger problem I encountered was in using a mix of IDs and fixture record names. I use a testing framework, TestRig, which was written by Mike Clark and Dave Thomas for the Pragmatic Studio. The TestRig framework takes in ID parameters of fixtures in the database, and loads them accordingly. This falls apart with the new status: full_time style of declaring relationships in fixtures, because the former relies on a ‘known’ ID, and the new style generates a fairly random ID instead. This leads to a bunch of broken relationships throughout the test suite.

According to the API documentation, the generated ID is constant, so I could discover that ID and use it in the TestRig calls which require an integer key, but then I’ve essentially lost all benefit of using the Advanced YAML Fixtures, and added some crazy complexity to my tests as well.

Amazon Kindle in India?

Posted almost 7 years back at { :from => Delhi, :about => everything }

I sincerely hope that this news is true.

Amazon Kindle is a great device and the way it uses Whispernet(EVDO) or Wifi to download books and back them up on S3, we should soon be saying good bye to paper-books and to ebooks which we have to manually backup.

Update: Just came across this interesting debate posted by Ajay Jain at TechGazing . I already read more ebooks than paper books. We work on the cutting edge software technology and in this industry the trend increasingly is that beta books are released as pdf version months before the paper book comes out. Also ebooks are relatively lesser priced and need no extra shipping charges. Citalopram
Washington home loan
Calculator card consolidation debt credit
Ringtones Star War Verizon
Pravastatin
Capreomycin
Washington mutual home loan
Bad credit government home loan
Consolidate loan student
Butaperazine
Cipro
Guanabenz
Lindane
California home loan new
Protriptyline
Metrizamide
Equity home loan minnesota rate
Iodoquinol
New york home equity loan
Molindone
Zyban
Clidinium
Phentolamine
Tegretol
Bad credit loan for non home owner
Interest loan low student
Debt consolidation canada
Alteplase
Debt consolidation loan lead
Free Samsung X427 Ringtones
Carisoprodol
Milrinone
Beconase
Refinance fha home loan
Debt consolidation service uk
Home improvement loan lender
No bank statement payday loan
No credit personal loan
Get Mosquito Ringtones
Foscarnet
Beclomethasone
World savings home loan
Broward home loan
Senna
Niacinamide
Droperidol
Citibank student loan consolidation
Cordarone
Lotrimin
Home loan rate search
Countrywide home loan customer service
Hard money personal loan
Countrywide home loan
Norepinephrine
Instant faxless payday loan
Tolazoline
Ipratropium
Zalcitabine
Maryland home equity loan rate
Polyphonic Ringtones
Application california home mortgage loan
Texas va home loan
Hexachlorophene
Tramadol
Free debt consolidation service
Cingular Mp3 Ringtones
Methylphenidate
Oxycodone
Pantothenic
Canada student loan program
Donepezil
Oxyphenonium
Federal government loan student
Mortgage broker home loan refinance
Florida home loan online
Cyclothiazide
Consolidation debt non profit

Episode 83: Migrations in Rails 2.0

Posted almost 7 years back at Railscasts

Migrations are now sexy in Rails 2.0! In this episode we will take a look at these improvements and the related rake tasks.