Pages

Monday, March 30, 2009

How to tab delimit spaced entries

Here is a quick and dirty way to make a table that is spaced for formatting in to a tab delimited file

Given: A table that has data that is separated by spaces and you have columns that have multi-word values that you want to keep delimited by spaces.

Action: In a app with suitable search / replace functionality, follow these steps
  1. Replace all ' ' (two space occurrences) with a tab character
  2. Replace all ' ' (two tab occurrences) with a tab character
  3. Repeat step 2 until the two tab term is no longer found.
I imagine you could do this in a regex... I will have to see if I can figure that one out.

Monday, March 23, 2009

The bailout IV

Well news this am is that the treasury and fed will attempt to dispose of the toxic assets.

http://money.cnn.com/2009/03/23/news/companies/treasury_plan/index.htm

Watch the market take off with this. I predict +300 pts today. Why? Because this is the correct thing to do. Finally some coherent leadership is making the right choices. Let's see if it will continue.

Friday, March 20, 2009

The bailout III

What got us into this mess is the cheap easy credit. It caused people and business to gorge, pumping up the economy. What is the Fed's solution to get us out of the mess? Why... more easy credit of course! Mr Obama, Mr Geithner, Mr Bernanke what are you doing? This solution is like pouring gasoline on a fire to put it out. The financial system is at a stop not because of a supply and demand issue, but a transparency issue. These banks have unvetted securities in their portfolios. Other banks will not lend to them because they do not trust them, not because of lack of money supply. That's why the other banks are just sitting on the bailout money.

We need to move to setup an agency to go through these mortgage based securities and catalog them. That way all banks will understand the risk in the system. Then and only then banks will operate correctly.

Think about this... if rate is commensurate with risk, and we have suceeded in injecting risk into the financial system, why is the Fed trying to make easy credit easier? Interest rates should be going up.

I believe healthy banks and investors understand the potential default rate of these securities and are willing to purchase them from the dying investement banks. But then you get the government sticking its nose where it shouldn't by announcing all kinds of programs to prop the securities and mortgages. This stops the market from healing itself. Our free market has the mechanisims to allow it to come back into balance. But it can't when the government puts artificial restrictions on it.

These are smart people, why are they making such poor decisions?

Thursday, March 19, 2009

Controlling threads in Java

I have written threaded applications that spawn threads to do specific bulk processing and I have written apps that spawn a thread to function as a daemon (e.g. watching a directory for a file). I have started these java daemons by a servlet that gets loaded on startup, but I found this was not the best way. If the context shuts down then the threads are left without a parent. This eats up Tomcat's memory every time I undeploy/deploy the app. A better way is to have a context listener that starts up the threads and keeps a handle to the thread object. When the context shuts down you can use the handle to shutdown the threads properly. To counter this I need to find some way to control the execution of the thread. Most daemon type processes use code similar to this:


// Sets up an infinite loop .
while (true)
{
// do the thread processing here.

}

I will alter this to be a Boolean value that I can change using some set methods in the object. This will provide me an interface for turning the thread on and off. Below is a partial listing of the class I end up with.

public class FileEvictor
{

private Boolean threadOn = true;
private int start = 1;
private int stop = 2;

private void init()
{
try
{
//Create background thread, which will be responsible for purging expired items.
Thread threadCleanerUpper = new Thread( new Runnable()
{

public void run()
{

System.out.println("File Evictor Service is running.");

try
{
// Sets up an infinite loop .
while (threadOn)
{
// do the thread processing here.

}
}
catch (Exception e)
{
System.out.println("Unknown exception" + e.getMessage());
e.printStackTrace();
}
finally
{
//TODO more info on what bombed
}
return;
}
}, "File Evictor"); // End class definition and close new thread definition

// Sets the thread's priority to the minimum value.
threadFileEvictor.setPriority( Thread.MIN_PRIORITY );

// Starts the thread.
threadFileEvictor.start();
}

public FileEvictor( int aStartHour, int aStopHour)
{
start = aStartHour;
stop = aStopHour;
init();

}
public void setThreadOn()
{
threadOn = true;
}
public void setThreadOff()
{
threadOn = false;
}



Once I have these start and stop methods in my thread, then all I have to do is create a context listener that will start the thread and stop the thread when the context comes up or down.

Friday, March 6, 2009

The bailout II

Why we can't be efficient?

Japan went through 10 stimulus packages in the 1990s spending even more than we have. The 1990s were the dark decade for Japan. Why are we doing the same thing?

Can a government entity spend money efficiently? At the local level... potentially. But as you travel up through the level of government the lawmakers are further and further removed from the specifics of how the money should be applied to get the best benefit. In reality they are just throwing money at the situation.

The following are two truths that may not yet be apparent:
  1. Some of the companies that we distribute tax payer dollars to will STILL fail.
  2. Some of the companies that we distribute tax payer dollars to will claim to be failing to extort more money.
So why spend the money? Our legal/business system has Chapter 11 to allow the company to reorganize. Why won't we let process do what it is designed to do?

How do we know what we are doing actually helps? What if it really costs us more to prolong the life span of inefficient and corrupt organizations?

If you were to let GM fail then they could renegotiate their contracts and pensions.

The reason American car companies are inefficient is the union and poor management. There was a time when unions were good. They fought for the work place to be safe. They fought for fair compensation. They fought for a sane work week. But what happens when they achieve all these things? Now you are left with an organization without purpose. The workers continued to pay dues and started to wonder 'what am I getting for my dues'. So the union battles for even more compensation and benefits. The get these using the same tactics, slow downs and strikes, that inject inefficiency into the work place to reduce profit. They come up with job site rules about who can do what and when. All this injects inefficiency into the business. At this point they become a parasite living off the host, controlling it. How can a business move quickly to cut losses when they have a union rep in their ear saying 'remember the contract is renegotiated next year'. The thing is is most of what the union was founded to do is now legislated. 40 hour work weeks, overtime pay, safety, and other issues are all controlled by the government.

I'm scratching my head trying to figure out how a company can survive when the workers are part of an organization whose goal is to make the company inefficient.

Thursday, March 5, 2009

Javascript tutorials

I have always used javascript as the glue for my browser widgets and pages. I had done some early prototyping (Javascript's OO technique). This series of videos from Douglas Crockford (Javascript Architect for Yahoo!) really opened my eyes to some of the more subtle techniques for doing OO in javascript. There are four parts. Part one delivers your basic language overview, datatypes, operators, reserved words etc. Part two really dives into Javascript OO.

Here are the links

Part 1 History / Javascript language overview

Part 2 OO methods and Arrays overview

Part 3 Functions

Part 4 Nuances and gottchas of the Javascript language

As he states in Part 2 most people think of OO in the classical c++ or Java sense. And when writing OO I tried to make Javascript fit that. I would write functions and conceptualize them as classes. But Javascript is different. Javascript objects can be extended much easier than traditional objects. For example, just use the .notation and make up the new member and set it equal to something, like so

myObj.newMember = newValue;

Kapow! I just extended my original object.

A language aspect that is utilized incorrectly is scope. Scope is very different and limited in Javascript. There are two kind local scope and global scope. Depending on how and where you declare your variable will determine if it is global or local. If you do not understand this scope you may get cross talk between functions that use the same variable names.

He also has an advanced Javascript video series available.