programming


Congress, had better start thinking about repealing their 1 trillion dollars in discretionary spending for next year’s budget.   My co-workers are complaining about the projected cost of heating oil in the Northeast.  They are already starting to stock pile food.   I sure hope that Congress does not return to the price controls of the Carter administration.   They only cause shortages.  We need Congress to stop raising the budget and start cutting.  What would really help everyone right now would be an energy tax credit.  People need to drive to work in many cases, and we do not have 30 years to wait for new rail lines.   People in the Northeast are going to need heating oil come October, so Congress had better start passing something now or else people are going to freeze to death this winter.  Maybe Dodd could let us stay at his place since he is getting such a good deal on his Countrywide mortgage.

I had a little fun with perl this weekend.  First I compiled the ta-lib which gives you access to all sorts of technical analysis functions like double exponential moving average.  While the library itself does not install the perl module like a typical module off of CPAN, it is easy enough to figure it out if you know a little bit about perl.  Second thing I did with perl is setup a script to take a file with historical price and volume data and graph it with gnuplot via a Tk interface.  This is really nice since gnuplot has some really great looking financial plots.  Here is a basic plot I created of Sprint since 1984.  What is nice with the x11 terminal and a pipe to gnuplot, you can quickly change the graphs in the window to show some other data.  This beats writing the data out to a file then loading it.

So I was up near a job re-training facility near Springfield MA. They had a list of companies from which employees could utilize their service if they were terminated. What jumped out at me was that the Federal Reserve Bank was on the list. That is right, the place that prints our paper money, is firing people. Top this off, I was on my way to lunch, and a lady comes up to me begging for money. I was shocked, I only saw this sort of thing when I traveled overseas to developing countries. This was Massachusetts. If my short riff was not enough to scare you, take a read of this article that included a discussion on a recent panel with Nouriel Roubini.Eye Opener

I recently was searching for a way to do kernel density estimatation. I came across a module for matlab, but I do not have a copy of matlab. I tried porting it over to perl, but I was having some problems getting the inverse discrete fourier transforms working in Math::FFT the way I wanted them to work. In the end, I ended up compiling the latest version of the R language 2.7.0 and then installing RSPerl which is a bridge to allow you to call R from perl and vice versa. One of the maintainers helped me out. There are some environment scripts you should source in your shell rc file first. Once you have that done, one of the perl modules that came with RSPerl had an extra =cut that I had to take out. The tie call in the RReferences.pm was not needed since no TIESCALAR was ever defined. After these small changes, the whole thing worked like a charm. I am including an example here since I did not find anything like it in any of the other examples. Given a sample of some random variable, this will perform a kernel density estimation using gaussian kernel. It will create a plot. Then it will dump the X and Y values seen in the plot to the screen. You can of course use these values for other things.

#!/usr/local/bin/perl -w
use strict;

# stuff to get R started
use R;
use RReferences;
&R::initR("--silent");

# sample of random variable
my $x = [1,2,2,3];

# do the kernel density estimation  $h will be the reference to the result
my $h = &R::callWithNames(”density”, {’x',$x,’kernel’,'gaussian’,'na.rm’,'TRUE’});

# plot the result
&R::callWithNames(”plot”, {’x',$h,’main’,'gaussian’});

# sleep for a few seconds so the plot window does not vanish
sleep(3);

# get the x values from the result object
my @xv = $h->getEl(’x');

# get the y values from the result object
my @yv = $h->getEl(’y');

print “X values\n”;
print join(”\n”,@xv) . “\n”;

print “Y values\n”;
print join(”\n”,@yv) . “\n”;

Today is the day that I put this blog up on a couple of places to get more exposure. I hope my posts on using perl for everyday things will help out the community.

Technorati Profile

I recently ran into a problem where a whole bunch of strange filenames with strange characters appeared in a home directory in linux.  Because the filenames had wildcards in the naming, it was a little tricky to delete them.  For instance say you have a file named   m?v?.   I initially thought I could use perl and stat to get narrow them down and unlink them.  However, the stat did not seem to return any data on these strange files.  My next idea was to use the octal display,   if you run a  ls -b   to display the file in octal you might see something like m\173v\002  to delete this you would type  rm m$’\373′v$’\002′     however, I ran into some filenames that still had strange characters with octal display.  My final solution was a windows / linux mix.  Since they were all created a specific time, the easy solution was to open up the directory in windows via Samba and then just sort by time, select, and delete.  This did the trick.

I was looking across some perlmonks posting, and I came across a reply to a post that seemed useful. Putting this in a crontab will automatically update the CPAN modules that you have installed in your system.

perl -MCPAN -e ‘CPAN::Shell->install(CPAN::Shell->r)’

I wanted to make a program to scan a particular folder in my outlook 2003 that holds messages placed there by a rule. However, due to outlook security, a pop up appears to confirm access to outlook when you try to access the emails. This is a major roadblock to automating email access on windows xp. I could not find a clear example on the web that used another pst file so I created this example. I hope this helps someone out down the line.

There is a solution called Outlook Redemption that solved the pop-up problem for me. You can install a copy on windows from the site http://www.dimastr.com/redemption/ .

Once you have this installed, make sure you have a copy of strawberry perl http://strawberryperl.com/ . I happen to use version 5.8 but I will switch to 5.10 soon. With this installed, you will also need the module Win32 installed, but this is easy since you can install perl modules with CPAN on windows when you have strawberry perl setup.

Here is the code that scans a different pst file called otherpst and a folder within that pst file called scanme

#!perl # windows notation

use strict;
use Win32::OLE;
use Win32::OLE::Const;
use Win32::OLE::Const ‘Microsoft Outlook’;
my $outlook;
eval {
$outlook = Win32::OLE->GetActiveObject(’Outlook.Application’)
};
if ($@ || !defined($outlook)) {
$outlook = Win32::OLE->new(’Outlook.Application’, sub {$_[0]->Quit;})
or die(”Cannot create outlook\n”);
}

my $namespace = $outlook->GetNamespace(’MAPI’);

# get the proper pst file
my $folder = $namespace->{’Folders’}{’otherpst’};

# now get the folder within the pst file
my $folder2 = $folder->{’Folders’}{”scanme”};

# get all the messages
my $msgs = $folder2->{Items};

# a count of the number of messages in the folder

my $ncon = $msgs->{Count};

# a redemption object that stops the annoying popup

my $tysonmaly = new Win32::OLE(’Redemption.SafeMailItem’);

my $con;

# for each message in the scanme folder print the body out to STDOUT

foreach my $ii (1 .. $ncon) {
$con = $msgs->Item($ii);
$tysonmaly->{’Item’} = $con;

# you can access other things like the subject or sent time or sender but this just shows body access

print $tysonmaly->{Body} . “\n”;

}