Sunday, September 7, 2008

Finding The Opposite Of A Regular Expression In Ruby

I don't know if it happened to you but there are some times when you want to find the contrary of what you have in mind, I mean the opposite (inverse) of a regular expression or everything except a certain regexp. Well, there is a way to achieve that with Ruby (and a lot of other programming languages):
/^((?!REGULAR_EXPRESSION_HERE).)*$/


For example, if you want to find every lines where the first character is NOT 2 to 4 "f" followed by "oo" and then "bar" somewhere else on the line, you can use:
/^((?!^f{2,4}oo.*bar).)*$/

Example:
"foo+bar"[/^((?!^f{2,4}oo.*bar).)*$/] => "foo+bar"

"fffoo+bar"[/^((?!^f{2,4}oo.*bar).)*$/] => nil

" fffoo+bar"[/^((?!^f{2,4}oo.*bar).)*$/] => " fffoo+bar"

"fffffoo+bar"[/^((?!^f{2,4}oo.*bar).)*$/] => "fffffoo+bar"


For the references, those ideas came from the Vim tips section here.

I hope this will help someone.

Saturday, September 6, 2008

Industrial Robot Controlled by Java (World's First)

Today I won't provide you with boring code but instead talk about something a lot of people would not believe possible. Some people already know that Sun has a commercial "Real-Time" system for Java. A group of people have developed a robot controller powered by Java. To achieve their goal, they used a commercial industrial robot from the ABB company: The ABB IRB 340 Flexpicker, one of the fastest (10 G of acceleration) robot in the world. Because seeing is believing, here is the video:

Click here to see the video

I was amazed! Now, can you imagine yourself hacking an industrial robot controller with your favorite Java IDE?