About Adam Young

Once upon a time I was an Army Officer, but that was long ago. Now I work as a Software Engineer. I climb rocks, play saxophone, and spend way too much time in front of a computer.

Leaving Haiti

Cover of the Koran

Cover of the Koran

I realize that last post left out the details of the QRF mission to the old Police Station, so I will start with that. As I stated, I had no idea why we went there. There was no riot, not problem, no emergency that justified commiting the QRF, unlike the numerous times we went to the POwer station. But, we went, we cordoned off the area, we searched it (it was abandoned) and then we cleaned it up. Yep. Soldiers from our Army went through, shoveled out the accumulated debris of decades and pulled out all of the contraband: there was none to speak of. One soldier went into MOPP Level Haiti: Rain Suite and Protective Mask. He was lowered into what must have been a sewer or something. We found lots of trivially interesting items like spent round casings and so on, but nothing that justified the search and cleanup efforts. Once we had the place ready for move in, we emplaced some more concertina wire and shuttled back to the main base in trucks. I queried the Battalion Commander about this and he stated that we had basically De-voodooed the big bad police building.

One measure of success for the United States was the ability to turn the mess over to the United Nations. After a couple months on Island we got word that this would happen relatively soon. The tented area on the far side of the Airfield had been populated by Guatemalan and Caribbean-Command soldiers. It was vacated, and soon a Battalion from Pakistan under the UN flag came to Cap Hatien. These were battle hardened soldiers from the Kashmir Region. As I mentioned, we were not carrying SAWs, never mind heavy machine guns. That was why it was strange to see them uncrate heavy machine guns and recoilless rifles.

My first opportunity to get to know our new neighbors came when a power surge fried the power supply on one of the computers in the Pakistani Battalion headquarters. Someone at Battalion asked me to go over and take a look at it, I guess since I was a Computer Science major at School. I was fairly sure there was nothing I could do. I’m not sure why the Battalion Signal Officer didn’t go over instead. Sure enough, the magic smoke had escaped the power supply and the machine was dead. There was a computer store in Cap Hatien, a fact that surprised me greatly. They were able to buy a new power supply off the economy and get the machine back up and running.

The better aspect of this trip was that I got a chance to talk to the Pakistani officers, see their quarters, and get a feel for them as a replacement unit. To this day I am grateful for the opportunity to put a set of faces, feelings, images and smell alongside the word Pakistan, even though I have never been to the country. Probably the most vivid mental picture I have is of the tents. The Pakistani soldiers slept on mats on the ground, really nothing more than insulation. Compared with our cots and the poly-pads we take with us to the field, it was spartan. I got the impression that this sleeping arrangement was the norm, not just in the field.

The officers from the Pakistani Battalion hosted the officers from our Battalion to dinner in their base camp.  After two months of Brown and Root, any thing would have tasted good, but I suspect that the meal we were fed would have competed with any India/Pakistan/Afghani food served in the States.  I’d never really understood the term feast before.  This was a Feast.  I remember most clearly the spiced lamb, but all of the food was superb.

I am nominally Jewish.  While in the Army, I was more observant than in the rest of my life, and have never really kept the fact secret.  The men from Kashmir were the first moslems I had encountered in my life, and I must say they made a stellar impression on me.  Beyond their fierce demeanor was a hosptiality and understanding I was not expecting.  When the matter of religion came up, I expressed my ignorance of Isalm and interest in learning more about it.  Capt Safraz Ali responded with a gift that means more to me than just about any other I have received in my life:  his personal copy of the Koran, pictured at the top of this post.  Here is his inscription:

Koran Inscription

Koran Inscription

People that might find it offensive to write in a holy book should remember that a true Koran is only in Arabic.  This version has translation into English, which makes it less than a pure Koran.  Thus it is acceptable under Islam to write in it.

The American forces were under very strict weapons control.  Before entering the base camp, we cleared our weapons, and then dry fired them into a barrel filled with sand.  It was understood that an accidental discharge of your weapon, even into the clearing barrel, and would get you into serious trouble.  The commander of the Pakistani battalion had an accidental discharge within the first week, a point that made some of the American officers snicker.  Personally, I suspect that they were just much more comfortable carrying weapons around, and didn’t take our over caution seriously.   Most of them had been in combat.  Very few of our soldiers had.

My last tour of tower duty had me checking on a tower inside the base camp, across from a mud-hut village that was fast encroaching on our space.  A woman on the outside was chatting up the tower guard.  When she saw me, she said, “Lieutenant, when you go back to America, take me with you.  Pakistani soldier mean.”  I guess we had done a decent job winning their hearts and their minds.

Not long after, we flew back to the states.  I remember pluggin MARC cards into the readers to create a manifest, a brief view of the airfield in Port au Prince, and that the flight crew on Tower Air were some of the same people I had seen on previous charter trips.  After a long flight home,  we disembarked at the Air Force Base alongside Pearl Harbor and took buses back to Schofield Barracks.   At Schofiled we had the Kiss-Ex: Ex being short for exercise, basically the reunion of the soldiers with their families.

Why I am excited about Obama

A friend of mine stated recently that, while she wouldn’t be pulling the lever for the McCain/Palin ticket, it was mainly due to Palin.  She wasn’t excited about Obama, and asked if I could say something to change that.  I’ve been ruminating about it all day, not because I didn’t have anything to say, but because I have so much, and I want to say it well.

Continue reading

My Ideal Technology Setup for work

“Since I’m dreaming, I’d like a pony” –Susie, in Calvin and Hobbes.

“I’m not just the President of the Hair Club for Men, I’m also a client.” –President of the Hair Club for Men

Not only do I write software, I use it. A whole bunch. I am a Linux guy, and when ever I end up in a situation where I have to work around a proprietary solution that just doesn’t make sense for what I am trying to do, it ads a point or two to my Diastolic. So here is my dream setup:

Continue reading

Skeptic

In the book Glory Road, Robert Heinlein has his protagonist cut lose his adopted son who doesn’t understand that “the world doesn’t owe him a living.”  Dan Miessler recently published a joke whose punchline was basically that individual responsibility was the hallmark of the republican party.

Continue reading

Transcribing Music using mpg123

A long time tradition for learning how to play like the great soloists is to learn their solos from recordings.  Ideally, you would listen to the recording slowed down.  However, on analog equipment, when you slow down the recording, you have to adjust the pitch back up, since you have effective dropped the frequency of the recorded notes.  With mp3 files, you have the advantage of having sampled the original recording into discrete chucks called frames.  Thus to slow down a recording, you can just tell your music player to double the number of times it plays each frame, and you have slowed down the playback without affecting the pitch.

Say you are a harmonica player and you want to learn John Popper’s solo at the beginning of Runaround.  You can do so by playing it back in mpg123.  Here’s the approach I would use.  Start by playing the song from the beginning:

mpg123 runaround.mp3

Now find the start of the solo.  To skip ahead, use the -k option to skip frames.  Try at about 1000.

mpg123 -k 1000 runaround.mp3

Now use a binary search:  If you hear the solo playing, go backwards, if you don’t go forwards.  At 1000 I hear it playing, so I go back to 500, then 250. At 250 I just hear the intro guitar, so I jump forward by 125 to 325 and so on until I figure out that the solo starts roughly at 270.  Now I slow down the playing by half:

mpg123 -h2 -k 1000 runaround.mp3

It is distorted as all hell, but I can make out the notes, and more importantly, match it on a piano, harmonica or saxophone.  I can slow it down even further with

mpg123 -h3 -k 1000 runaround.mp3

Which is as far as I would want to go.  Note that for older recordings, where the solo may be exclusively on the left or right track, you could add the -0 or -1 options to shut out more of the background noise.

As you progress, you want to move forward in the song.  Use the -v option to display frame information as you play.

OVER keyword in Oracle

I’m looking at the SQL Scripts that create and modify the database for VPXD. Specifically, I am looking at the oracle version stats[123] scripts. They included a query that uses the “OVER” keyword and I have not found a decent description of what this keyword does. This is the query:

SELECT
st.counter_id AS COUNTER_ID
,v_time_rowid AS TIME_ID
,ST.STAT_VAL AS STAT_VAL
,DENSE_RANK()

OVER (PARTITION BY ST.COUNTER_ID ORDER BY SM.SAMPLE_TIME DESC) AS DENSE_RANK
FROM vpx_sample_time1 sm,vpx_stat_counter sc, vpx_stat_def sd, vpx_hist_stat1 st
WHERE sm.rollup_counter=to_number(to_char(v_start_time_id)||to_char(v_cnt))
AND st.time_id = sm.time_id
AND st.counter_id=SC.COUNTER_ID
AND SC.STAT_ID=SD.ID
AND ((SC.DEVICE_ID =v_null_device_id and v_stat_rollup_level<3) or (v_stat_rollup_level>=3))
AND SD.STAT_LEVEL<=v_stat_rollup_level
AND SD.ROLLUP_TYPE=3)
WHERE DENSE_RANK=1

;

The one description of the Over command I have found has come from the Microsoft website:

“Determines the partitioning and ordering of the rowset before the associated window function is applied”

OK, so it is a union of two types of functionality: partitioning and ordering. The queries I am looking at use both. Let’s start with partitioning:

PARTITION BYDivides the result set into partitions. The window function is applied to each partition separately and computation restarts for each partition.

The window function in this place must somehow refer to DENSE_RANK. To me this looks like it is possibly trying to insert a subselect into the overall select. Here is how MSDN defines DENSE_RANK. I’d like to reiterate that these are Oracle functions I’m trying to understand, and Microsoft is doing all the work explaining them. When I tried executing this SQL Query in SQLPLUS via the Oracle 11 instant client, it balked:
SQL> 2 3 4 5 6 SQL> SP2-0734: unknown command beginning “OVER (PART…” – rest of line ignored.
SQL> SP2-0734: unknown command beginning “FROM vpx_…” – rest of line ignored. It parses fine when I do it as part of a plsql stored procedure.

Time to dig out the slightly larger guns: I picked up a copy of the SQL Cookbook by Anthony Moliaro from Our Friends in Sebastopol, CA. This covered both DENSE_RANK and the OVER keyword.

Over, it turns out, is one of a new set of functions added to SQL 2003 that the Standard calls Windowing functions. This means they operate on a subset of the results returned from the outside query. The best example I saw showed if you are selecting all employees from all departments, and next to each one you wanted to show how many employees were in that department, you could use count(*) with an over clause that specified PARTITION by department. This example is in the Cookbook.

DENSE_RANK () tells you how many rows come before the current row in some ordering scheme. The over clause is used to define that ordering scheme. If two rows have the same rank, they have equivalent values according to DENSE_RANK. For instance, if we have five people with five salaries, their DENSE_RANK of salaies will be 1 through five, highest to lowest. If the top two salaries were identical, top rank would return 1,1,2,3,4.

OK, so it looks like the original query wants to use DENSE_RANK on a subset of the returned rows of the query. The window will be defined by this portion of the clause: PARTITION BY ST.COUNTER_ID

And the order within this window will be determined by: ORDER BY SM.SAMPLE_TIME DESC

OK time to get serious about playing:

I’ve learned a little but since the above frustrations trying to run the stored procedure. Here’s what I do now:

run sqlplus. For me this is

/home/adyoung/apps/oracle/instantclient_11_1/sqlplus adyoung/adyoung@10.17.195.159/DRORACLE

Now make it so anything I print to the screen is visible:

set serveroutput on

Load my sql file in and execute it.

get myfile.sql

/

OK, I have a development method. To print debugging output:
DBMS_OUTPUT.PUT_LINE(‘Text Here’);
And we can debug. In the time honored tradition of always moving from success, I comment everything out but a simple output statement. In this case, I know that the real code uses a variable for the rollup level, so my File (minus commented out section, looks like this:
create or replace procedure stattest
is
v_stat_rollup_level int;
begin
v_stat_rollup_level := 2;
dbms_output.put_line(‘Value: ‘ || TO_CHAR(v_stat_rollup_level));
end stattest;
Which executes using the above method. Now I start adding in parts of the SELECT.
SELECT st.counter_id AS COUNTER_ID FROM vpx_hist_stat1 st;
Of course, it hates this. When I load it into sqlplus I get:
Warning: Procedure created with compilation errors.
Of course, in order to see these compilation errors, I have to jump through a couple more hoops:
SQL> set arraysize 1
SQL> set MAXDATA 6000
SQL> show errors procedure stattest
LINE/COL ERROR
——– —————————————————————–
6/1 PLS-00428: an INTO clause is expected in this SELECT statement
So I add a variable called maxcounter in the declare section and modify my select:
SELECT
max(st.counter_id) into maxcounter
FROM
vpx_hist_stat1 st;
dbms_output.put_line(‘Maxcounter: ‘ || TO_CHAR(maxcounter));
And I have a procedure that executes and does something. On to the rest of the select. After several iterations of trial and error, I have the SQL query wokring as a cursor. I’ve now figured out even a better way to work. I’ve modified my file like below, and can now cat it into the sqlplus interpreter:
set arraysize 1
set MAXDATA 6000
set serveroutput on

create or replace procedure stattest
is
v_stat_rollup_level int := 2;
maxcounter int := 0;

CURSOR MYCURSOR is SELECT
st.counter_id as COUNTER_ID,
st.STAT_VAL as STAT_VAL
FROM vpx_sample_time1 sm,
vpx_stat_counter sc,
vpx_stat_def sd,
vpx_hist_stat1 st

WHERE
st.time_id = sm.time_id
AND st.counter_id=SC.COUNTER_ID
AND SC.STAT_ID=SD.ID
AND SD.ROLLUP_TYPE=3
AND SD.STAT_LEVEL<=v_stat_rollup_level;

begin

open MYCURSOR;

FOR recname in MYCURSOR
LOOP
dbms_output.put_line(‘Value: ‘ || TO_CHAR(v_stat_rollup_level));
END LOOP;

dbms_output.put_line(‘Maxcounter: ‘ || TO_CHAR(maxcounter));

end stattest;

/

show errors procedure stattest

.

OK, I am going to bail here.  This post has been half written for a while, and is not going to get completed anytime soon.  I think I’d vote “Over” as something that would be useful in the next rev of postgres, if only for simplifying porting from Oracle.

Dependency Licenses

The following script, when run on a RPM based system, tells you what licenses your application might trip by linking with other code.  You have to  set $MYEXE to som path to an executable.

for LIB in `ldd $MYEXE | sed -e ‘s!.*=>!!’ -e ‘s! (.*!!’` ; do rpmquery –whatprovides $LIB ; done | grep -v “any package” | sort -u | xargs rpmquery –qf %-30{NAME}:%{LICENSE}”\n

Here is a sample run for perl:

glibc                         :LGPL
perl                          :Artistic or GPL

Note that this is only for the linked files that are registered with RPM.