Kategorien
Programming

Execute shell commands in Ruby

On Ruby Quicktips there´s a nice sum up of the three different ways how to execute shell commands from your ruby code. It´s explaining very well the differences between exec, backticks (or %x shortcut) and the system command: Execute Shell Commands

If you need more exhaustive info concerning the three possibilities, the article is listing three links to other resources on the web:

Kategorien
Allgemein Programming

MS SQL / T-SQL: Get a random date

Lately I needed to get a random date from an MS SQL Server, and it was a real pain to find something on google about it. Luckily I stumbled upon the blog of Ben Nadel who has written a great article about Getting A Random Date From A Date Range In SQL.

Kategorien
Programming

Ruby 1.9: Displaying a MessageBox Using the Windows API

On Ruby on Windows there´s a fantastic article on Displaying a MessageBox Using the Windows API. This working fine on Ruby 1.8, but unfortunately it is resulting in an error like this when being executed with Ruby 1.9:

message_box.rb:20:in `[]': wrong number of arguments(2 for 1) (ArgumentError)
   from message_box.rb:20:in `message_box'
   from message_box.rb:25:in `'

Luckily I´ve found a solution on the Ruby-Forum: Ruby 1.9.0 problem with DL.dlopen, in short, replace lines 20 + 21 of the example code by the following:

msgbox = DL::CFunc.new(user32['MessageBoxA'], DL::TYPE_LONG, 'MessageBox')
r, rs = msgbox.call([0, txt, title, 0].pack('L!ppL!').unpack('L!*'))

Kategorien
Programming Testing

Generate Unit Tests automatically (?)

For quite a while I´m thinking about a solution for following situation:
I have a lot of (old) scripts/ classes, which I created without unit tets (yes, shame on me, but by the time I´ve written them, I didn´t knew better, or didn´t had the time to do so, … the usual excuses).
Now I would like to add unit tests afterwards, to benefit from all the advantages they give to a programmer (find regression, give a safety net, etc.).

But I´m just too lazy to go all of my code and add unit test after unit test after unit test. Instead I would like to auto-generate them. At least the skeleton, like test classes & methods; so e.g. create a test method for every method used, create a test for every object that should be (not) accesible from the outside, etc.
I know that I will have to create the test logic by myself, so checking if a method returns the expected result (or not).

Before start coding a solution, I would like to know if there´s something existing like that already? If yes, I would appreciate any hints/ links/ articles etc., especially for Ruby, but Java and/ or C# would also be great.
Thx in advance!

Kategorien
Book Learning Programming

Programming Skills

Not only Ruby is a great programming/ scripting language to do your daily jobs or to automate your testing tasks, also Perl is.
Find a free (GNU Free Documentation Licence) Perl training as HTML or PDF on the homepage of Greg London

Also Python is a great language, and a lot of free books & tutorials are existing to learn it, e.g. Learn Python The Hard Way by Zed A. Shaw, which can be downloaded as PDF. But please be aware that this is a book for absolute programming beginners!

Via http://www.schockwellenreiter.de/