REVERT TO CONSOLE


Revert to console for language translation

Posted in Uncategorized by reverttoconsole on April 17, 2009

“Do I really need a web browser or collection of clunky travel dictionaries to translate to and from different languages of the world?  Isn’t there a command line tool that can do the same thing and make my life easier, while making me even more awesome at the same time?”

The answer is YES!

The <a href=”http://savannah.nongnu.org/projects/twandgtw”>Translate Word and Graphical TW project</a> is your gateway to having superior translation capabilities right in your CONSOLE!

Download tw from http://savannah.nongnu.org/files/?group=twandgtw.
I’m using tw-0.1.3.tar.bz2.

Major Dependencies
elinks
http://elinks.or.cz/download
I’m using elinks-0.11.5.tar.bz2.

I’m using Cygwin and I was missing the following:
curl
libiconv
util-linux random utils (For the getopt() function)

The above Cygwin packages can easily be obtained through the Cygwin setup program.

1. Extract elinks.  Build it starting with “sh configure”.  Then type “make”.  After it finishes, type “make install”.

2. Repeat step 1 with tw.

3. Type tw -h to test that everything is installed correctly.

4. If everything went well, try typing “tw en-es hello” and you should get the following output:
hello : hola

You’re all set!  Now you can quickly translate between many languages straight from your bash shell.  Type “tw -l” to see a list of “all” the languages.

Customized Script for Google Translate

Google’s translate service is one of the most comprehensive language translators available.  A major benefit of using Google’s translation service is that you can pass in as much text as you want; simply surround the text with quotes.  Even though tw does not list all of the languages that Google supports, it is still a bash script that parses input parameters, and it does not do any validation.  You can append anything you want to the argument “translate.google.com”.  For instance, Croatian is not listed as one of the languages (“hr”).  However, all you need to do is append the appropriate language pair to the end of the argument string, like so:
$ tw translate.google.com.en-hr hello
zdravo

To make this a bit more user-friendly, I have created a simple wrapper script (twg) for tw that only uses Google’s translate service.  It works just like tw, except you do not have to type “translate.google.com”.  You only need to put in the language pair.  For example:
$ twg en-es “Hello World”
Hola Mundo

Type “twg -l” to get a complete list of supported languages. You can find more details about featured languages at http://www.google.com/help/faq_translation.html#langpairs.

<code>
$ cat twg
#!/bin/bash
# author: eokuwwy
# http://reverttoconsole.com
# description: customized tw wrapper script that uses google translate

if [ "$1" = "-l" ];
then
echo “Arabic=ar”;
echo “Bulgarian=bg”;
echo “Catalan=ca”;
echo “Chinese=zh-cn”;
echo “Chinese=zh-tw”;
echo “Croation=hr”;
echo “Czech=cs”;
echo “Danish=da”;
echo “Dutch=nl”;
echo “English=en”;
echo “Filipino=tl”;
echo “Finnish=fi”;
echo “French=fr”;
echo “German=de”;
echo “Greek=el”;
echo “Hebrew=iw”;
echo “Hindi=hi”;
echo “Indonesian=id”;
echo “Italian=it”;
echo “Japanese=ja”;
echo “Korean=ko”;
echo “Latvian=lv”;
echo “Lithuanian=lt”;
echo “Norwegian=no”;
echo “Polish=pl”;
echo “Portuguese=pt-BR”;
echo “Romanian=ro”;
echo “Russian=ru”;
echo “Serbian=sr”;
echo “Slovak=sk”;
echo “Slovenian=sl”;
echo “Spanish=es”;
echo “Swedish=sv”;
echo “Ukranian=uk”;
echo “Vietnamese=vi”;
elif [ "$1" = "-h" -o -z "$1" ];
then
echo “Usage: twg [sourcelang-destlang (i.e. en-es)] [term]“;
echo “twg -h (shows help)”;
echo “twg -l (shows language list)”;
else
tw translate.google.com.$1 “$2″;
fi
</code>

Happy command line translation!  Now jailbreak (at your own risk) your iPhone/Blackberry/PDA and put tw on there!

$ twg en-es “peace out”
a la paz

JBoss Seam presentation at the Boston Java meetup group

Posted in Seam by reverttoconsole on April 5, 2009

If you’re around the Boston Metro area, drop in for my presentation on JBoss Seam at the Boston Java Meetup group @MIT EHS office, Cambridge.

Click here for more details.

CAPTCHA Overview and alternatives

Posted in Security,Web by reverttoconsole on March 9, 2009

I recently evaluated CAPTCHA for a client requirement. Here is a brief overview (Source: blogs, wiki, white papers found on google search)

CAPTCHA stands for: “Completely Automated Public Turing test to Tell Computers and Humans Apart”. It refers to a technology familiar to anyone who’s registered on a popular website – the “what word is shown on this image” challenge. As the “Turing test” alludes to, the purpose is to distinguish between humans and computers. Types of CAPTCHA:

* Photo/Image CAPTCHA
* Animated CAPTCHA
* Sound CAPTCHA
* Multiple choice questions
* Logic questions

CAPTCHA doesn’t prevent hackers or attackers to the site. It merely attempts to prevent bots and spammers.

How does CAPTCHA work?

(more…)

Multiple Gmail Inboxes

Posted in Tools by reverttoconsole on February 15, 2009

This caught my eye recently as a nice addition to the gmail labs.

I’ve been using a second inbox as a todo-list, filtered on starred items. I can also prioritize tasks based on different stars.

Mapping a clob type in hibernate and oracle 9i/10g

Posted in Con-(in)sulting,Hibernate,Java,Spring by reverttoconsole on February 11, 2009

The easiest way to map a CLOB type of Oracle to a pojo in Hibernate, is to setup a user defined type in Hibernate, which converts Oracle’s ClobType to a String and vice versa. So you’re pojo’s property is going to be a “String” type. There are only two steps to setting this up:

1) Write the Clobtype User defined type

[java]

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

public class ClobType implements UserType {

public int[] sqlTypes() {
return new int[] { Types.CLOB };
}

public Class returnedClass() {
return String.class;
}

public boolean equals(Object arg0, Object arg1) throws HibernateException {
boolean ret = false;
if (arg0 == null || arg1 == null) {
ret = false;
} else if (!(arg0 instanceof String) || !(arg1 instanceof String)) {
ret = false;
} else {
ret = ((String) arg0).equals((String) arg1);
}
return ret;
}

public int hashCode(Object arg0) throws HibernateException {
return arg0.hashCode();
}

public Object nullSafeGet(ResultSet arg0, String[] arg1, Object arg2)
throws HibernateException, SQLException {

String ret = null;
StringBuffer buffer = new StringBuffer();
try {
// First we get the stream
InputStream is = arg0.getAsciiStream(arg1[0]);
byte[] buf = new byte[1024];
int read = -1;

while (is != null &amp;amp;amp;&amp;amp;amp; (read = is.read(buf)) &amp;gt; 0) {
buffer.append(new String(buf, 0, read));
}
if (is != null) {
is.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
throw new HibernateException(&amp;quot;Unable to read from resultset&amp;quot;, ioe);
}
ret = buffer.toString();
return ret;
}

public void nullSafeSet(PreparedStatement pst, Object data, int index)
throws HibernateException, SQLException {
data = data == null ? new String() : data;
String in = (String) data;

byte[] buf = in.getBytes();
int len = buf.length;

ByteArrayInputStream bais = new ByteArrayInputStream(buf);

pst.setAsciiStream(index, bais, len);

}

public Object deepCopy(Object arg0) throws HibernateException {
String ret = null;
arg0 = arg0 == null ? new String() : arg0;
String in = (String) arg0;
int len = in.length();
char[] buf = new char[len];

for (int i = 0; i &amp;lt; len; i++) {
buf[i] = in.charAt(i);
}
ret = new String(buf);
return ret;
}

public boolean isMutable() {
return false;
}

public Serializable disassemble(Object arg0) throws HibernateException {
return (String) arg0;
}

public Object assemble(Serializable arg0, Object arg1)
throws HibernateException {
return this.deepCopy(arg0);
}

public Object replace(Object arg0, Object arg1, Object arg2)
throws HibernateException {
return this.deepCopy(arg0);
}

}
[/java]

2) Hibernate mapping: Update the type in your hbm file or annotations accordingly. The example here maps a property “label” to oracle column “label”

[xml]

[/xml]

That’s it. Since there is no dependency to anything else, it should work in a Spring environment too.

Note to Oracle 9i users: You might get the following exception:
java.sql.SQLException: operation not allowed: streams type cannot be used in batching

Solution? Use use 10.1.x drivers. Oracle 9i drivers have a known issue regarding the same, which they only fixed in 10.x. It’s believed that Oracle’s 10.x drivers are downward compatible with Oracle 9i (unlike 11.x drivers).

amazon kindle 2 first impressions & review — it sucks

Posted in Rants by reverttoconsole on February 9, 2009

Amazon is the best place to buy books, cds, electronics and other memorabilia. But what happens if you want your hands in all the pies?

After a sloppy launch of Kindle 1, a year ago, Amazon released Kindle 2, hoping that it would be the next best thing, something of a revolutionary device like IPhone. Dreams. Stephen King introduced the product at the launch; I was waiting for Kate Perry next, who would sing “I read a book, I sucked at it.”

Amazon — please respect people’s intellect. We are not buying acne creams.

Ok. Some features:

  • No Touch screen.
  • Larger screen? It’s smaller than a book. the screen is double that of your IPhone. 35-40% real estate wasted on the device. Just look at the picture once. Why? Because there’s a keyboard on it. Yes — A KEYBOARD.
  • Too many buttons. There are seven buttons on the device. Remember Microsoft Vista? There were seven options too — logoff/sleep/hibernate/shutdown/whatever1/whatever2/hangMyself.
  • Displays in B&W.
  • Operating System? Inspite of being based on Linux, this still is one black box where you can read a book, one at a time. More cameras are going to have built in wifi, smart phones are becoming mini computers, cars can park themselves. If someone thinks they want to make a “revolutionary” product that will change the landscape of the world and there is no software to manage the device. What is the point of having an OS when you can’t have software running on it?
  • No API for third party applications. Imagine the applications built around reading books, social networking, custom viewers, virtual bookshelves or even mini applications to store your favorite quotes from books. I expect a dedicated ebook reader (the one that claims “version 2″) to be smarter than just displaying books in black and white pages. If you had inbuilt wifi, and a browser, you could probably get “recommendations” or lookup a dictionary or even sort your library according to genre. It’s quite naive that Amazon limits the device to such a small scope. Imagine Playstation releasing PS4 and it only plays Sony games downloaded from Sony store and all the games are arcade games, single player. And they are 16-bit color.
  • Stylus? Don’t you want to mark your favorite sentences? Or do you want to click menu->highlight->cursor down (12 times)->press spacebar (on the keyboard!) 17 times->press another button to “highlight.” Now, did I say, there was another button to save it?
  • foldable lcd screen or flexible displays? No. It looks good for a 1999 ipod equivalent of an ebook reader.
  • Doesn’t read pdfs or any other format.
  • No Wifi or browser.
  • Can you do anything apart from reading books (bought from amazon?) – No. Same reasons as above.
  • Does it read books in your own voice? No. There’s a robotic voice which is worse than the “your call is important to us. Please hold, while ….”

Fine, this is a book reading device. I get it. But what’s special about it? What’s so “groundbreaking” about it that I should stop buying books and buy a Kindle? I haven’t seen a single Kindle in subways, libraries or Starbucks, in the last one year. The original Kindle sales are not disclosed to public, clearly seems like a catastrophic failure for a product that had hopes of “changing the way people read books, forever.”

It seems like a step back to the lalaland with outdated technology and mediocre features. For 350$ and seven buttons and a keyboard and a black n white display and lack of add-on software, its a bad investment one could ever make. Amazon raves about saving 5-10$ on a book, but never counts on the 10$, one would get when the same book is sold. We read books. We share books. We give it to our friends. We distribute them. Reading & sharing books is a culture. We need products that can enhance this experience and add more value, not redefine it for someone to be a monopoly. I can’t believe Amazon thinks that “Kindle” is still the future of reading … I just can’t. The worst strategy than Microsoft. They thought, that the whole world will “browse the web” in IE.

As for me, my admiration and honor goes for a little unknown company that developed Stanza for IPhone/IPod, for FREE. If only Amazon had 1% of their passion …

Some pics here.

Finally Figured Something Out About Ubuntu

Posted in Linux by reverttoconsole on January 25, 2009

This has been an annoyance for a while…

When I fired up a terminal in Ubuntu, it did not automatically load ~/.bash_profile (and therefore not ~/.bashrc either). I just noticed that if you edit the Default profile (Edit->Profiles->Edit), and select the Title and Command tab, there is a checkbox option to “Run command as a login shell”. I checked that and it magically took care of the problem.

The DO NOT’s

Posted in General,Rants by reverttoconsole on January 23, 2009

I haven’t posted in about 8 years or something like that. Besides being lazy and uninspired, I really haven’t learned anything new or exciting in the past 2 years. I have nothing to share that would be beneficial to all of you.

However, some of you may benefit from what I have learned NOT to do over the past 2 years. I have learned plenty of “DO NOT’s” over time, but the last 2 years, especially the last 7 months has been the grand festival of “DO NOT’s”.

1. Do not let an “expert” with unsubstantiated credentials tell you how to do your job. Better yet, avoid working with an “expert” whenever possible. These “experts” like to talk down to you and blame you for everything that goes wrong. They never admit to contributing to the problem. They also insist that his/her approach is the best, even if God (or other supreme being) were to tell him/her that it’s wrong. An “expert” will try to control you and the project at any cost. An “expert” will no doubt run the project into the ground or into a persistent vegetative state. If you find yourself working with an “expert”, take precautionary measures and have an escape plan.

2. Do not let users perform their daily job duties with an application that is not fully developed or production ready, especially if it’s not even beta ready. Don’t let users rely on an application that is undergoing constant development and hasn’t even been tested. Users will no doubt work their dirty little hands into your project and get you to make changes at the drop of the hat, because their jobs depend on it! Don’t expect a manager to help you out in this situation. If things have reached this point, no manager can simply stop this evil cycle. Now you have a situation where there is a direct impact on the success of the company. Because the application is not even fully developed or tested, there will already be bugs galore. The users relying on your application will find even more bugs that stop them in their tracks. Everything becomes a critical defect. Trust me, if you get into this situation, you will want to die, because you are already dying a slow and painful death.

3. Do not develop in an environment that has absolutely no process. You don’t need to be process gung-ho and implementing CMMi level 5, but you should have some basic sort of SDLC process in place. A development group without processes usually fails to have standards as well. The “as long as it works” mantra comes into play.

In this situation, you will end up with horrible spaghetti code where developers are doing whatever the hell they want. You will have no ability to monitor code quality. You might end up with code that looks like it was written by someone who is half-way through their first programming course (CSCI 101). Hey, they just learned how to write arrays, and want to show off that skill, as much as they can. Your “code review” will take place when you have to take over their project, at which point you’ll ask yourself, “What kind of dumbass could possibly write this &*@%!@#!!!????” Of course by then the bad code has permeated its way into the deep inner bowels of the application, like a virus, making it nearly impossible to correct without throwing it all away and rewriting from scratch. It’s sort of like when Windows gets jacked-up every year or so and your best solution is to “format C:” and start over.

In addition, the extent of your QA will probably be limited to the success of your compiler and a few keystrokes and mouse clicks.

no process = bad applications (hopefully most of you know that already)

4. Do not get involved in a project where a phone call, simple face-to-face conversation, or a note on your desk from a user is all that is required for you to make a change. This is closely related to #3, but it’s worth emphasizing a bit. You need to have a way to document change requests and prioritize those requests, even if it a simple excel spreadsheet on a shared network drive. This is just one more way that you can be trampled to death by users. Not to mention the fact that you are developer and you have no business answering the phone or communicating with a user directly. That’s what BA’s are for. You lack the people skills required to interact directly with users and you should be damn proud of that. Additionally, there is great satisfaction to be had when you can make users punch themselves in the face. By that I mean something like this:

User: “What is this thing doing? That’s not the way it’s suppose to work!”
You: “Yes it is.”
User: “No, it’s not.”
You: “Yes it is, you requested it, see?”
User: “Ah DAMMIT!” (punches self in face)

5. Do not succumb to the “at least we still have jobs” outlook on your career. Yes, the economy sucks right now and layoffs suck. I hate seeing people bringing in boxes to pack up their stuff, especially when they have done a great job at the company for 10, 15, 20 years or more. That’s like saying, “Thanks for all your great years of service, now be a team player and piss off, yeah?” There are other things employers will do to cut costs though. They might squash benefits, slash salaries, and eliminate incentives. This is especially likely to happen if the executives made stupid decisions (likely in any case) that ran the company into the ground. You don’t have to pay for their mistakes. This industry is still viable. You can find good opportunities elsewhere. Don’t be afraid to explore and don’t feel bad for leaving. If you really believe in the company and feel that you want to help “get through this tough time together”, then stay and try to maintain a positive attitude. But remember, you don’t owe the company anything.

That’s it for now. Maybe you learned something, maybe not. You may have only learned that I am just an ass, if you didn’t know that already. Either way, I hope it wasn’t a boring read. I’d better get back to “work.”

My Screen

Posted in *NIX,Tools by reverttoconsole on January 23, 2009

Screen is a great tool for command-line usage, and is also available for cygwin. If you enjoy using the command line, and haven’t checked out screen, I highly recommend it. I found some of the commands and configuration changes a little difficult to remember, so I’m adding them here.

First of all, the main screen escape key is ctrl-a. That’s all well and good, unless you’re an emacs user, then it’s downright offensive (ctrl-a is the emacs command to go to the beginning of a line- one I happen to use a lot). Fortunately it’s easy enough to change. I added a screenrc file that looks like this:

[bash]
# ctrl-/ is my preferred shortcut key
escape 3434
# turn off visual bell
vbell off
caption always “%H %= %-w%L>%{= BW}%n*%t%{-}%52<%+w %L=”
startup_message off
deflogin on
shell -/bin/bash
[/bash]

It’s easy enough to switch between screens from a single (rxvt) shell now, but as an emacs user I naturally enjoy having my screen split so I can multitask. It took me a while to figure out how to do that effectively with screen.

ctrl-/ S splits the screen.
ctrl-/ n switches to the next screen, but does it within the current region, so it’s not like M-x o in emacs.
ctrl-/ tab switches between the split regions, just like M-x o in emacs.
ctrl-/ X “unsplits” the screen.

References

Emacs Macros 101

Posted in *NIX,Tools by reverttoconsole on January 20, 2009

Macros are really useful for programming, but since adopting Eclipse I haven’t been using them as much, much to the detriment of my fingers.

For a while I used Notepad++ for macros. Macros are easy to use with Notepad++, but unfortunately you’re limited to trivially simple macros- for example, you can’t “search” your way through a file changing every double-quote to a single-quote. In Emacs, you can do whatever you do in emacs as a macro.

“C-x (” is analogous to the record selection in Notepad++. It means your next commands will be recorded as a macro.

When you’re done, “C-x )” tells emacs to stop recording.

“C-x e” runs the macro you’ve just recorded.

Once you create a macro, you’ll probably want to run it more than once… “C-u some-number your-command” will execute “your-command” exactly “some-number” times. This can be used to run the command “call-last-kbd-macro”. So, for example “C-u 1000 C-x e” will run the macro you just created 1000 times (or until the end of the file, whichever comes first).

Next Page »

Follow

Get every new post delivered to your Inbox.