Tuesday, November 2, 2010

Where Are My File Extensions

Due to some seriously strict email servers, I was unable to send a .zip file in an email. It was being blocked by the individual I was sending it to's server (poor English).

The easy solution was to rename my file james.zip to james.allow, faking the mail server out so it wouldn't be blocked. On the other end, the user could just alter it back from james.allow to james.zip and bam, problem solved.

However I was unable to rename my file in Windows using the right click -> rename feature. If I changed the file james.zip to james.allow, it would call it james.allow.zip. Being ignorant to all things simple, I was unaware that Windows hides the file extensions from you by default.

The way to add those file extensions into your file names, so you can rename the file extension, is to go into Windows Explorer->Tools->Folder Options->View (tab) and uncheck the "Hide extensions for known file types" box. Once you do this, all your files (with extensions) will appear and you can rename james.zip to james.allow to successfully get it across.

Tuesday, October 26, 2010

Visual Studio Basics - DLL's

Just starting to go to work on Visual Studio. Was receiving an error when I was running a program that said, "This application has failed to start because libfrsdk-8.1.0d.dll was not found. Re-installing the application may fix this problem."

First for dll's, they seem to be the .NET equivalent of JAR files. Dynamic Linked Libraries. What this error seems to be saying is that it can't find the library needed to execute the code. Sort of like a ClassNotFoundException in Java (may be a bit of a stretch).

One option was to add the folder housing the libfrsdk-8.1.0d.dll to my PATH variable but that seems kind of ehhh. Why should I alter an environment variable when most of the shit I do isn't going to need this .dll file?

Another option and the one I went with was to add the .dll to the same folder that houses my actual application. Pasting in the appropriate dll did the trick when I ran the program.

So the last question you may have if you're totally ignorant on Visual Studio and whatnot is "how do I know what folder has my application?" Visual Studio when you build/compile creates a Debug folder underneath your project. This Debug folder contains all sorts of interesting files, most importantly an Application type file with the name of your program. Pasting the dll's in this Debug folder did the trick for me.

More to come I'm sure as I attempt to become savvy in .NET

Monday, October 25, 2010

How to Remove Security Tool Virus

Was doing some totally legit website surfing (guitar tabs, thank you), and got a pop-up saying a virus had been detected and that a scan was running to find the problem. These items were masquerading as legitimate Windows programs. The name of the running program was simply "Security Tool".

Don't believe the hype, it is a virus and it is trying to force you to purchase their tool (via credit card) to remove the virus (which it just created). Very dodgy shit. Once you enter in your credit card information who knows what gets done with it. Totally illegal.

Not only did Security Tool constantly pop up after I closed it saying the same message over and over, it also managed to completely take over my Internet access and stop my antivirus programs from running. Fortunately I had an IPhone so I was able to search for solutions.

The simplest way I found to get rid of it and regain internet access was this:
1) Stop the computer and restart it with booting options (F-12 in Windows).
2) Start the computer in Safe Mode with Networking (because you'll need the Internet).
3) Download MalwareBytes' free product and make sure it is updated to the most recent version.
4) Run a full system scan with MalwareBytes. This will find the evil files and remove them. It will take around an hour to complete.
5) Select all the items the program found and remove them using the MalwareBytes tool. (Seriously these MalwareBytes people are awesome!)
6) Restart your computer normally. You should no longer see any evil messages and whatnot, the virus should be removed and you should be good to go now.....
7) EXCEPT!!! When you try to launch the Internet, you'll be unable to. This is because the virus does some ignorant shit to force your internet requests to go to a proxy server (the evil virus' proxy server...this is how they control your internet access).
8) The way to turn this proxy server off differs depending on your browser, but for Google Chrome, go to Wrench Icon -> Options -> Under the Hood -> Change proxy settings -> LAN Settings (similar for other browsers I suspect)
9) Uncheck the "Use a proxy server for your LAN" button and "OK" out of those windows. Now when you restart your browser you should have your internet back.

Simple as that. Thanks to MalwareBytes for totally being wonderful human beings.

And whoever the a-holes are that created the Security Tool virus/trojan horse/malware that is taking over peoples computers and stealing credit cards.....you're pieces of trash.

Friday, October 22, 2010

Ant Javac stops Compiling when fork=true

This one was a beast and unfortunately I still don't have any definitive answers as to why this happens. I had an Ant javac task with the following attribute:


fork="true"

When I would run Ant, it would say that it was starting to compile, and then it'd just stop. My class files would never be generated, but it would not have an error explaining what went wrong. (For the record there were more attributes, blogger doesn't accept the javac xml tag though....trust me, all the other attributes were right as rain.)

I tried playing around with setting an executable attribute, ensuring it was pointing to a javac executable (when you set fork = true, you're telling it to compile externally). This didn't work either. I turned on verbose logging by going into Eclipse->External Tool Configurations and setting -verbose as an argument in the arguments section of the configurations. This spit out a bunch more detail, but still nothing helpful.

The javac process would start without error, it'd list all the .java files that it found that needed compiling, and then stop. No error, no warning, just hang there doing nothing.

After much playing around, I found out that if I removed the fork attribute everything would work fine.

Unfortunately that's all I've got for you. I've wasted 8 hours on this thing and still am not closer to why this happens. If anyone happens to know why this is happening please let me know. I've tried altering JAVA_HOME's, default JDK's being used, etc. I've tried increasing the amount of memory......

I give up. If you experience this problem, where javac hangs without error and without completing, try making fork="false".

Tuesday, October 19, 2010

Clever Way to Handle SimpleDateFormat ParseException

I was having a few issues dealing with dates and XMLGregorianCalendar objects. Here's what went down.

I had a method that was parsing String dates and placing them into XMLGregorianCalendar objects. In order to get the XMLGregorianCalendar object created, you can use something similar to this code (You'll be forced to catch DatatypeConfigurationException):

GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
DatatypeFactory dataTypeFactory = DatatypeFactory.newInstance();
XMLGregorianCalendar xmlCal = dataTypeFactory.newXMLGregorianCalendar(gc);


The above code will give you the current time in an XMLGregorianCalendar object. Unfortunately I needed to accept a String date (like: 6/10/2010 5:40:30 PM) and use that instead of the current time.

The way you do this is the following (you'll be forced to catch ParseException AND DatatypeConfigurationException):

Date date = null;
SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy hh:mm:ss a")
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
date = dateFormat.parse(
"6/10/2010 5:40:30 PM");
gc.setTime(date);
DatatypeFactory dataTypeFactory = DatatypeFactory.newInstance();
XMLGregorianCalendar xmlCal = dataTypeFactory.newXMLGregorianCalendar(gc);


The issue was, different dates were coming back in different formats (crappy but I don't control the String passed in). So one date would be 6/10/2010 5:40:30 AM and another would be 7/11/11 5:40. When the method tried to parse a date without an AM/PM specifier, ParseException would be thrown. Very lame.

The way I've come up with to handle this is to place several SimpleDateFormat objects in a list and order them most specific to least specific (the term granularity is popping up in my mind). You can add as many SimpleDateFormat objects to the list with different patterns as you'd like.

Here is my complete example code that handles this:

private XMLGregorianCalendar getXmlGregorianCalendarFromString(
String stringDate)
{
XMLGregorianCalendar xmlCal = null;
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar
.getInstance();
Date date = null;
DatatypeFactory dataTypeFactory = null;

List dateFormatsList = new ArrayList();
dateFormatsList.add(new SimpleDateFormat("M/dd/yyyy hh:mm:ss a"));
dateFormatsList.add(new SimpleDateFormat("M/dd/yyyy hh:mm:ss"));
dateFormatsList.add(new SimpleDateFormat("M/dd/yyyy hh:mm"));

for (SimpleDateFormat dateFormat : dateFormatsList)
{
try
{
date = dateFormat.parse(stringDate);
gc.setTime(date);
dataTypeFactory = DatatypeFactory.newInstance();
xmlCal = dataTypeFactory.newXMLGregorianCalendar(gc);
// If we've made it here we have everything we need to proceed
// so break from the loop
logger.warn("Successfully parsed the date: " + stringDate
+ " with the format: " + dateFormat.toPattern());
break;
}
catch (ParseException e)
{
logger.warn("Failed to parse the incoming date: " + stringDate
+ " given the format: " + dateFormat.toPattern()
+ " attempting another date format. ");
continue;
}
catch (DatatypeConfigurationException exception)
{
logger
.warn("An error occurred generating a DatatypeFactory object. ");
}
}
return xmlCal;
}


There may be some hiccups to the above method (I only need 3 possible date formats), and if a better way exists to handle multiple SimpleDateFormats let me know, but I gotta say, it's more flexible and simple than I thought it could be.

Monday, October 18, 2010

Increase Server Startup Timeout in Eclipse

I was receiving a Server startup timeout in Eclipse when I started Tomcat. It was complaining that startup took more than 45 seconds so it wouldn't start at all.

Trickier than I thought to alter this setting as I couldn't find in the the Preferences->Server section.

If you want to change the startup timeout in Eclipse, the way to go about it is to double click on your server in the Servers tab. This pops up a window with a lot of nice options to configure. Click the Timeout arrow, increase the timeout to be more than 45 seconds, and that's all there is to it.