All Things Techie With Huge, Unstructured, Intuitive Leaps

Giving a user an anonymous ID programatically

We have a web application written in Java whereby when the users sign in, we want them to be anonymous to each other.  So what we do, is give them a number.  I needed an algorithm to generate the number from their database user id, and I wanted the algorithm to vary such that it wasn't that easy to figure out.

So what I do, is on even days of the month, the user id is added to the day of the month, and on odd month days, I take the absolute value of the day of month - the user id.

//get day of month

int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
//cast it to a double so that I can get a modulus 2 which indicates whether it is even or odd
double amem = (double) dayOfMonth;
if ((amem % 2) == 0) {       // it's an even day with no remainder
dayOfMonth = dayOfMonth + userId;
} else {
//its an odd day
dayOfMonth = Math.abs(dayOfMonth - userId);

Hope this helps someone.

Toshiba Laptop Mouse Won't Work

I was logged in via Remote Desktop to one of my Caribbean servers.  The browser window was being blocked by the Remote Desktop banner or task bar on top of the screen.  I couldn't close it.  So I Googled how to close an application window.  It said to press Alt + F4.

Well on this stupid Toshiba laptop with the weird keyboard, F4 also needs a function key press as well.  The normal key for F4 is to switch display modes when you are connected to a projector.

So I pressed Fn + Alt + F4 and my browser closed.  But I must have let go of the Fn key.  The cursor froze.  The mouse wouldn't work.   I am talking about the mouse on the finger pad.  It is a Synaptic pointing device.  So I shut down the computer and re-started it.  No dice.  I restarted in Safe Mode.  Still had a frozen cursor.  Took out the battery, and re-started it with the last good configuration.  Nada.

I figured that I had blown the drivers.  I went to another machine and did some googling.  It said that Toshiba had a mouse lock. It said to press Fn + F9.  I did.  Nothing happened.  I tried Fn + F4.  My cursor unlocked.

Hope this helps someone.  It sure wasted a bit of my time.

Virus Free For 5 Years -- Thanks Free Avira

Someone on a forum asked about trojans and viruses.  I posted the following:

My 5 cents on anti-virus:

We needed a computer to act as a server in Nassau. We went to the Radio Shack. It was a Radio Shack in name only. The guy paid the franchise fee and sold whatever he wanted. He was selling a brand new Pentium knock-off complete with Microsoft Office, Adobe Photoshop, Macromedia Director -- everything, The machine was just over $300, and with those software packages, it should have been over $2000.

I brought it back to the office, plugged it in, and every single machine on the network alarmed about spyware, trojans and viruses trying to get in. It turns out the software was crack software from China, embedded with viruses.

The machine was so virus laden, that the browser was hijacked. You couldn't physically go to many anti-virus sites. I download a virus killer onto a USB stick, and ran it from there. That gave me my browser back. But every single machine in the network was still alarming. I used a router to create a subnet to isolate the machine, and I went to work.

We had a bought copy of Norton and MacAfee. That didn't do the trick. We downloaded everything, and still couldn't get a clean machine. I removed all of the software -- Microsoft Office, Adobe Photoshop, everything. Finally there was one free on that worked. It was the free version of Avira out of Germany. I have that on all of my machines today, and it performs wonderfully. It blocks even the most sophisticated attempts to get in.

And then on top of that, I started using Google Chrome exclusively. The infection rate went to zero. 

Since I am a data privacy advocate (I quit Linked In and Facebook), I went to the free Google Chrome store and downloaded tracking cookie blockers. Some of them don't let me buy on Expedia, but when I have to use online shopping and it doesn't work, I temporarily turn them off from icons in the tool bar.

Since I have the free version of Avira, every day I get a huge pop-up with an ad from Avira. I can live with that because it lets me sleep nights. I earn my living with my computer, and I have to protect my digital assets. Speaking of which, you should go to the store, buy a cheap USB key and put your digital books on it. Then put the key in a safety deposit box or in another location other than your house.

I have been trojan and virus free for five years.  Thanks Avira.

Linux Sendmail Not Working

It's real easy to send email using a linux server.  We have an app where we need to send notification details to our users so we send it via the linux server that is already running Apache Tomcat.

Since the details and notifications go beyond the simple, we use java to write the details to a temp file, get the email address from the database, invoke a bash shell to send the mail and then delete the temp file.

Here is how its done.

String messbody = (new StringBuilder(String.valueOf(messbody)))
.append("Please log into to see the latest things on your account.").toString();

Then I generate a random file name by assembling a bunch of random characters:

int rancharacter = 65 + (int) (Math.random() * 90);

char ck = (char) rancharacter; 
String fnum = String.valueOf(ck); 

I did the rancharacter many times to generate a random string.  I created a linux directory where this would be written to.  It is in /home/messages.

String longfileName = "/home/messages/" + fnum; 
 File f = new File(longfileName); 
 try {
 BufferedWriter bout = new BufferedWriter( new FileWriter(longfileName)); 
 } catch (IOException e)
 { System.out
 .println("Writing email file exception");
 System.out.println("Exception " + e.getMessage()); }

Now that I have a file, I wrote a very little bash script called mailer, put it in the /bin directory and did a chmod so that it could be executed.  The bash script looks like this:

#FILE= "/home/messages/$3"
#echo $(basename "$2")
mail -s $(basename "$2") $(basename "$1") < /home/messages/$(basename "$3")

The only thing life to do, is to create a subject, get the email, get the runtime so that one can execute a linux command, and send the email.

Here's some code:

String emailAddress = email;   //previous declared variable that went to the database
 String subject = "Account_Notification";  //I had to put the underscore to eliminate space problems
 String messBody = fileName; 
 String cmd = "mailer" + " " + emailAddress
 + "  " + subject + " " + longfileName; 
  // get the linux runtime to execute the command
 try { Runtime run
 = Runtime.getRuntime(); Process pr = run.exec(cmd);
 pr.waitFor(); BufferedReader buf = new
 BufferedReader( new InputStreamReader(
 } catch (Exception fu) {
 System.out.print(fu.getMessage()); } 
 boolean success = f.delete();

OK - all of this was working.  Then I changed the message body and it stopped working.  What caused it to stop working.  In the body of the message, I put java.util.Date.toString();

That would stop Centos linux from mailing.  Weird.  I hope that this helps someone.