Friday, May 6, 2011

USB OTG : Create your own cable

First of all, we need to understand what is USB OTG (On The Go). USB OTG is a protocol which enables electronic gadgets (such as mobile phones, cameras, pen drives) to communicate with each other through USB. As you would understand normally these gadgets get connected to a computer (which is called a 'host') as a peripheral (which is called a 'slave').

But in the USB OTG; some of these gadgets (which would normally play the role of 'slave') can act as 'hosts' for other gadgets.

Now a problem arises. How does a gadget (such as your smart phone) get to know the role which it needs to play (ie should it play as the host or the slave)? To answer this problem, we need to look at the pin assignment in a USB port.

A USB cable has 4 wires. 1 pair for power and another pair for data. But if you observe a mini or micro USB port which comes in a gadget like a phone or a camera, you will notice that there are 5 pins in the port. Apparently one pin is extra. That extra pin which happens to be the 4th pin (in between ground and data- pins) is the key.

If the extra (4th pin) is kept unconnected, the gadget will assume the role of the slave. This is the way a phone connects with a PC. If the 4th pin is connected to ground, the gadget assumes the role of host. This is how you need to connect a phone(host) with a pen drive (slave).

Now another important question, why do we need to create a DIY USB OTG cable? Number of mobile phones supporting USB OTG is very low. Also the number of users who are aware of USB OTG facility is even lower. Further many phone manufacturers do not not provide an OTG cable with the phone itself. Therefore it is very difficult to find a USB OTG cable in Sri Lankan market. As per my understanding only Nokia agents have this cable in their head office store at a very inflated price of about Rs 2000. But from Fort you can buy a normal USB micro (data) cable for Rs 200 and a normal USB (Regular) extension cable for Rs 100. Then you can make a USB OTG cable with only Rs 300 and litle bit of labour.

Therefore simply what we need to do in order to make a USB OTG cable out of a normal USB micro cable and a USB extension cable is
  1. Crack open a micro USB connector and connect 4th (extra pin) and 5th (ground pin) pins.
  2. Replace the male USB connector with a female one so that gadgets like pen drives can be connected (We need the the regular USB extension cable to salvage the female connector)
Now connect your smart phone with pen drive or other gadget and enjoy. By the way, did I mention that, your smart phone should support USB OTG?

Monday, May 17, 2010

Perfect java IDE for beginners

We have many java IDEs. Netbeans, Eclipse, IntelliJ being the most popular.

I'm an ardent netbeans follower. But there was a pressing problem in my mind about IDEs. What is the best IDE for a beginner; for a person who learns java?

The problem with Netbeans, Eclipse and IntelliJ is that they are meant for adavanced programmers. They are production tools and not learning tools.
  1. They have cool yet 'not good for beginner' features like code completion
  2. They have a rather complicated 'project structure' for the code. In other words they are not meant to write small 1 page, 1 file programs.
  3. They are huge programs

Other option for the beginner is to program using a text editor, compile via command line. This is good but the beginner need to learn more 'techy' stufff like command line args, vim etc. This is very troublesome for the teacher.

So what we need a bare bone level IDE which
  1. Does not have code completion and support
  2. Facilitates writing short 1 page, 1 file programs without a complicated project structure.
  3. Can compile the code with a single click
  4. Should be smaller in size

Recently I came across 'Jcreator LE' which is free and crippled version. Yep that is crippled by removing features like code completion and that makes it the ideal IDE for learners.

Friday, November 20, 2009

VPN configurations for internet addicts

Preamble :

One of my friends have blogged on how he managed to connect via VPN and to generic internet in parallel.

http://tdevinda.blogspot.com/2009/11/whats-inside-what-virtualization.html

This ended up in bringing a nice discussion on routing, VPN and VMs.

Following is my solution.


Issue :

Under normal conditions; when you get connected to a VPN, it is not possible to get connected with the internet.

Reason:

When you get connected to the VPN, automatically it is set as the default route.


Solution:

  1. Once you are connected to VPN, remove the default route for VPN. Under linux vpn is normally tun0.
  2. Then add a default entry for your usual network interface. (eth0, ppp0, etc)
  3. Then add the routing entry for the specific IP or the subnet which you need to get connected through VPN for tun0

Friday, October 16, 2009

Installing IE 8

Installed IE 8 in my office pc. (Yes I do use Fedora in my laptop, but the PC at office is still windoz xp). I am an avid follower of firefox. But my job includes testing web pages in many browsers. Earlier I was using IE6. But it was a pain to use it as it had no tabs. So after putting it off for many months, finally I decided to have the plunge.

Installing was a pain. If I participated in testing IE8, I will never give OK for it. There are many improvements to be done.
1. Installing process is awfully lengthy. In fact, an OS can be installed within that time.
2. There is no progress bar in the installation dialog, only a scrolling green worm like bar. So you got no idea whether installtion is actually in progress or something has gone wrong and installer is not responding.

Functionality seems still OK. In fact I'm writing the blog, via IE8. :-)

Hats off for Linux

I decided to use Fedora in my Laptop. The biggest hindrence I had to shift to Fedora from Windoz is now solved. You can plug and play USB HSPA modems now. Now hassles, just plug it and it works, even faster than on windoz xp.

This facility is available in Fedora 11 and Ubuntu 9. Guess most of the new Linux like Oss should have this.

Sunday, August 16, 2009

C++ with netbeans

Few steps should be followed to integrate C++ with netbeans in Windows

1. Download and install MinGW
2. Download and install msys

  • MinGW is the C/C++ compiler
  • Msys is some kind of a unix emulator. After installing it and setting it in the path system variable, you can input unix commands such as mkdir, ls in the dos prompt. This is needed as makefile in C++ needs to access unix commands.

3. In the compile command dialog in netbeans provide the MinGW bin directory for base. Then it will identify C and C++ compilers other than the makefile. You need to provide the makefile.exe in msys/bin as the makefile location.

Then as the K&R said in their famouse C book, "if you have not botched anything, it should work" :-)

Saturday, August 15, 2009

JSP importing class and jar files

Using java class files in jsp files

1. Put the class files in WEB-INF/classes/ folder

2. Import the class as <%@page import="."%>

3. Call that class as you would do in a normal java program

eg:

<%@page import="test.Hello"%>

<%
Hello heloo = new Hello();
String myName = heloo.SayName();
out.println("From scriptlet : "+ myName + "\n");
%>





Using a jar file in jsp

1. Put the jar file in lib folder.

2. Import the jar file as <%@page import=".*"%>

3. Call the class as .

eg:

<%@page import="jarTest.*"%>

<%
jartest.Main m = new jartest.Main();
String name = m.getName("Pinda");
out.println(name);
%>


Monday, August 10, 2009

Vive la Netbeans

Following day's I was completely worries and frustrated with my bad experience on web services with Eclipse plugging for Axis.

Found a solution today. It is netbeans. Really nice and I love the way it creates the implementation from wsdl file.

Saturday, August 8, 2009

axis2 plugins for Eclipse

I wasted a complete day by trying to do a web service using them.

It is a complete bad job. There are no complete set of jar files in lib folder. When the site says it is version 1.4.1 but when downloaded it is shown as 1.3.

Followed 2 tutorials published by WSO2. Oops, only the frustration is left.

When you do something, do it properly.

Tuesday, August 4, 2009

A simple SOAP client

The program is written in C#.

You can find a java client in http://www.cafeconleche.org/books/xmljava/chapters/ch03s05.html

The below code will not work just by copying and executing. If you are familliar with C# will get the idea.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Net;

namespace WWeb
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();

doc.Load(@textBoxIn.Text);

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(textBoxURL.Text);

req.Headers.Add("SOAPAction", "\"\"");

req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
Stream stm = req.GetRequestStream();
doc.Save(stm);
stm.Close();
WebResponse resp = req.GetResponse();
stm = resp.GetResponseStream();
StreamReader r = new StreamReader(stm);

richTextBox1.AppendText(r.ReadToEnd());


}

private void buttonIn_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
textBoxIn.Text = openFileDialog1.FileName;
}
}
}

Saturday, August 1, 2009

Creating a table from a query

The method varies according to the DB you are using

Oracle:

create table t_newTable as select * from oldTAble;


mySQL:

create table t_newTable select * from oldTAble;


MSAccess:

SELECT * INTO t_newTable FROM oldTAble;

Thursday, July 30, 2009

Sample code for accessing mySQL from java

import java.sql.*;


public class DBConnect {

/**
* @param args
*/
public static void main(String[] args) {

Connection connection = null;

try {
String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver
Class.forName(driverName);
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/databaseName", "userName", "password");
}
catch (Exception e) {
e.printStackTrace();
}

Statement stmt;
String s;
String own;

try {
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM pet");
while (rs.next()) {
// Get the data from the row using the column name
s = rs.getString("name");
own = rs.getString("owner");
System.out.println(s + " owned by " + own);
}
}
catch (SQLException e) {
e.printStackTrace();
}
}

}

Tuesday, July 28, 2009

My adventures with DB

First step

I was introduced to MS access when I was about 12 years old. To be frank I understand nothing then.

Rebirth

My 2nd introduction to DB was when I was 24 to Oracle. since then I have been studying DBs.

Following is solely my opinion and I do not recommend anyone to follow them. Of course no liability what so ever will be admitted.

MS Access

Our little friend. The best place to get started with DB.

Pros:
1. Intuitive interface
2. Easy imports and exports to other file formats.
3. Easy installation
4. No maintenance

Cons:
1. Poor SQL interface
2. Cannot be used as fully pledged DB server


MySQL
The free guy with lot of talents

Pros:
1. Free
2. Production level DB server
2. Easy to install

Cons:
1. No built GUI


Oracle

Pros:
1. Production level
2. Free version is available

Cons:
1. Messy to maintain.
2. Messy to get started
3. No built in GUI


DB interfaces

DB interfaces add GUI to oracle and mySQL servers

Toad for mySQL

Pros:
1. Free
2. Easy installation
3. Intuitive interface

Cons:
1. One query at a time
2. Importing data from other file formats is bit poor.

Toad for Oracle

Pros:
1. Good functionality
2. Concurrent connections
3. Lot of tools to manage the DB

Cons:
1. Cluttered window. Not even slightly intuitive
2. Free version is a crippled version


SQL developer

Pros:
1. Free
2. Nice object browser
3. Very intuitive interface

Cons:
1. Support only xls and csv file imports

PL/SQL developper

Pros:
1. Intuitive interface

Cons:
1. Lower level support for maintenance

Tuesday, March 24, 2009

Intergrated light out : HP proliant

HP proliant servers come up with an interesting remote management tool : iLO

The inbuilt one is the basic iLO which is a crippled version of advanced iLO. Basic iLO does not have many feature such as remotely viewing the screen and mounting remote media.

You need to purchase a license for the Advance iLO. As an option you may get a free evaluation licence for 60 days.

One of the disadvantages I observed in iLO is that its screen is not very sensitive. That means it cannot recognize if you move the mouse fast across the screen

Sunday, December 7, 2008

Error 530 Must perform authentication before identifying USER in FTP

This is one of most annoying issues you face when using ftp server in Red Hat linux. The solution is very straight forward.

Open the gssftp file. It is normally located at /etc/xinetd.d

Change the line "Server_args = -l -a'

to

"server_args = -l"

Then restart the ftp server

Saturday, December 6, 2008

Changing appBase in Tomcat 6

AppBase is the location where the Tom cat server searches for jsp files when called by a client. Default location is the webapps folder in tom cat home.

Changing this appBase involves bit of identifying the architecture of tom cat.

First thing you should remember is that every web application you are going to deploy should be in a separate folder. You cannot directly use that folder as the appBase. Instead you have to use parent folder.

eg: If your web application is at C:/myWebApps/firstwebApp, you have to use C:/myWebApps as the appBase.

Then calling the file C:/myWebApps/firstwebApp/hello.jsp can be done by http://localhost:8080/firstwebApp/hello.jsp


If you want to call the file C:/myWebApps/firstwebApp/hello.jsp just typing the URL http://localhost:8080/hello.jsp you have to rename the folder 'firstwebApp' with 'ROOT'.

Sorry for the lengthy description but first things first.

Then how to change the appBase.

  • Open conf/server.xml file in the tomcat home foulder.
  • Find the line containing Host name="localhost" appBase="webApps"
  • Change webApps with the parent folder of your web application folder.
  • Restart tomCat

Tuesday, December 2, 2008

Command line

Command line, MS DOS prompt, bash or any other command line utility should be familiar to you. AS most of people say they were used in ancient times. But still we use them, don't we? If we are using ssh what else do we have?

Need for a new generation of command lines

We all are familiar with IDEs. They provide us lot of helps when coding. Can't we create a ssh client that would help to type commands. For example when we type 'c' it should provide help listing all the commands starting with c along with their arguments.

Is there a tool like that? Or will I have to create such a tool?

Monday, December 1, 2008

Puppy Linux

I was looking for a good light weight OS to be used in virtual PC. Yesterday came across 'puppy linux'. Puppy linux is so small with only 96MB. Loads into RAM and runs pretty fast.

Still I'm studying puppy linux. Await more details.

Tuesday, November 25, 2008

Essential software for a PC running on windows XP

First software I would ever install would be MS Office 2007. I have used few office packages, but MS Office 2007 is unparalleled. Especially I find Onenote very useful for me.

Second software would be Mozilla Firefox. Nothing much to say. Simply it is the best. With add-ons you can do virtually anything with it.

Third is a pdf reader. If possible a pdf creater as well. Adobe is the best. Foxit reader is good as well.

Then I would go for a good text editor; ie a notepad replacement. Ultra edit is the best text editor I have ever used. Column mode, enhanced search facilities and the ability to handle very large files are specialties of UE. JEdit and Crimson editor are good free alternatives for UE.

Then it is the time for a good file manager. File manager is an enhanced version of inbuilt my computer or windows exlorer. Most file managers support two frames and tabs. Two frames helps you to perform copy and paste operartions easily and tabs give you less clutter when working with many folders. FileAnt and Explorer2 are very good user friendly free file managers.

A good compression utility is essenstial as well. 7zip, winzip and Winrar are good compression utilities. I personally prefer 7zip

Test from scribefire

Found this. Let's give a try.

It is working.

Now this text is typed off line. Let's save this. Done

When
I open it back... I can find the saved note. Also I can preview my blog
in an environment similar to blogspot. That means offline preview!
Wonderful.

Ok let's try to publish this.

Yea it is working :-)