Should’ve Been A Cowboy

I bet you’ve never heard ole Marshall Dylan say
Miss Kitty have you ever thought of running away
Settling down would you marry me
If I ask you twice and beg you pretty please
She’d of said Yes in a New York minute
They never tied the knot
His heart wasn’t in it
He just stole a kiss as he road away
He never hung his hat up, at Kitty’s place

I shoulda been a cowboy
I shoulda learned to rope and ride
Wearing my six-shooter, riding my pony, on a cattle drive
Stealing young girl’s hearts
Just like Gene and Roy
Singing those campfire songs
Oh, I should’ve been a cowboy

I might of had a side kick with a funny name
Running wild through the hills chasing Jesse James
Ending up on the brink of danger
Riding shotgun for the Texas Rangers
Go west young man, haven’t you been told
California’s full of whiskey, women and gold
Sleeping out all night beneath the desert stars
With a dream in my eye, and a prayer in my heart

I shoulda been a Cowboy
I shoulda learned to rope and ride
Wearing my six-shooter, riding my pony on a cattle drive
Stealing young girl’s hearts
Just like Gene and Roy
Singing those campfire songs
Oh, I should’ve been a cowboy
Oh, I should’ve been a cowboy
Oh, I should’ve been a cowboy
Oh, I should’ve been a cowboy…

Should’ve Been A Cowboy—Toby Keith

Somehow seeing a [SAS] header on a video being marked as NTF training, makes me remember that someone in [SAS] hosted a F&M exercise in GR1, and filmed it. I remember it being posted in the forums back in ’09. Now if I could just remember whether it was Valroe or Sniper who filmed it, lol.

Sometimes you can only laugh or cry

Today is one of those lovely days, you know, the kind where you would rather …

Day started off with having to take the car in for emissions inspection. The usual being badgered well in advance. Got maybe five or six hours sleep, depending on what hour it was when I finally dozed off. Garage declined to do the inspection, because of steel belting showing through the tyres and the front end being so far out of alignment that the bay chief didn’t want any of his techs putting it on the dyno. That means driving over to the mechanic and dropping about $230, plus picking up a pair of aft tyres later on. I’m still counting down the hours until my mother can figure out something venom filled over that one. When I was loading the car for tomorrow and noticed it leaking a bit of anti-freeze, I couldn’t help but laugh. It’s so fucked I can’t do anything else, except cry and I would rather laugh until I cry. At least that’s the best of both choices.

Obviously the most cheerful thought of my whole day, is of course: my mother wondering if I’ve any money she can barrow or anything of value to haulk in a pawn shop. The fact that anything I have to offer, is likely on her collateral with a loan company being aside the point. I intend to call a few pawnshops and see what they will take for a few bits of electronics, that I doubt will carry much of a price. All my life, I’ve never been alotted anything of value (unless you count friends tangibly). Like I’ve got anything to pawn, that isn’t a piss in the bucket?

It’s nice, when I need help, she will sit on her fat ass for half a year. When I turn to the job issue, she’s another obstacle. However when she needs something, she’ll all but sell my plasma to the first bidder. Ain’t love grand? Undoubtedly, I point out that if she wants help out of me, she shouldn’t have pissed away my time on the whole license/job thing. I wonder if they still buy human hair.

My original plan for the day, was to just work on getting as much of a small coding project (that I really need to get done), than focus on the job issue for the next several days, distracted by my workload. With my mothers near perfect commu’ block, I don’t expect that to work out very well. Trying to get a call through this place is futile and she keeps it that way. Between my mother and everything else, obviously nether objective has gotten done today. Some people have fun gaming or partying, coding relaxes me and I enjoy it.  No one seems to be able to understand that, except for more my kind of people. Those are rare.

It makes me fucking sick. I’m not good enough to care about, only good enough to be used. That’s what life here is like. I would do well, if I learned how not to care. Even better, odds are, if I learned to be amoral and give up on my concepts of right/wrong, ethics, and the like. Sometimes I hate being me. Unlike a lot of people on the earth, it doesn’t matter if you can be of use to me or not, I care about you the same either way. Like I say, I have only one face.

This reminds me, I really need to get the razor out of moth balls…. I’m starting to look like this guy.

backtrace

Why am I looking in the freezer for paper towels?

Because I’m happy, that’s why.

My replacement headset has finally arrived

The other day I was thinking about a young semi-student programmer that I know, and thought about presenting him a small set of “Teeth cutting” exercises. Small tasks that would serve a double purpose, help me evaluate his present aptitude for development tasks, and try and prepare him a wee bit for what his future education is likely to throw out. Unlike what seems to be the most common norm in college environments, I can also gently push in more, ahem, practical directions that what most students I’ve met have learned. I still have yet to find out if the number of stupid programmers on earth is due to the schooling or the students. Alas, that’s drifting off topic.

When I stopped thinking about the whole teeth cutting thing, I had done so because no ideas of what to use as a starting exercise had come to mind. Today while chatting, one did: a bare bones version of the UNIX tail program.

(06:30:27 PM) Spidey01: A first exercise:
 language: your choice
 description: implement a program called ‘tail’ that displays the last N lines of a file, where N is supplied by the user. It need not be a GUI, but can be if you wish.
 goals:
  A/ Minimise the scope your variables are accessible from.
  B/ Describe the procedure (algorithm) you came up with for finding the last N lines in the file.
  C/ Think and discuss, is there a way to improve on your algorithm?

Tail is complex enough that some C implementations are horrendously overcomplicated, yet simple enough that it is an easily completed without a gruelling mental challenge. Especially if the -n option is the only one you care about. The choice of A was chosen it’s a very common foul up among programmers, young and old a like.

I wrote a more complex program that that in C years ago as a learning process, that was more or less a fusion of the unix cat, head, and tail programs. Since the student in question was using Visual Basic .NET (oi), I opted to use C# so as to keep things at least, in the same runtime family. Here is a listing of the example code I wrote, the display here was done by feeding it into gvim and using :TOhtml to get syntax highlighted HTML to post here, than clipping a few things, hehe. The gvim theme is github.


  1 /**
  2  * comments having // style, are notes to young readers.
  3  *
  4  * CAVEATS:
  5  *  line numbers are represented by int, and thus have a size limit imposed by
  6  *  the 32-bit integer representation of the CLR.  Whether the users computer
  7  *  will run out of memory before that is irrelevant.
  8  *
  9  *  If there are less lines read than requested by the user, all lines are
 10  *  displayed without error message. I chose this because the error message
 11  *  would be more annoying than useful.
 12  */
 13 
 14 using System;
 15 using System.IO;
 16 using System.Collections.Generic;
 17 
 18 class Tail {
 19     enum ExitCode { // overkill
 20         Success=0,
 21         Failure=1,
 22         NotFound=127,
 23     }
 24 
 25     static void Main(string[] args) {
 26         if (args.Length != 2) {
 27             usage();
 28         }
 29 
 30         using (var s = new StreamReader(args[1])) {
 31             try {
 32                 var n = Convert.ToInt32(args[0]);
 33                 foreach (var line in tail(n, s)) {
 34                     Console.WriteLine(line);
 35                 }
 36             } catch (FormatException) {
 37                 die(ExitCode.Failure,args[0] + ” is not a usable line number”);
 38             } catch (OverflowException) {
 39                 die(ExitCode.Failure, args[0] + ” to big a number!”);
 40             }
 41         }
 42     }
 43 
 44     static void usage() {
 45             Console.WriteLine(“usage: tail.exe number file”);
 46             Console.WriteLine(“number = number of lines to display from “
 47                               +“end of file”);
 48             Console.WriteLine(“file = file to read from tail”);
 49             Environment.Exit((int)ExitCode.Success);
 50     }
 51 
 52     // Instead of doing the display work itself, returns a sequence of lines
 53     // to be displayed. This means this function could be easily used to fill
 54     // in a textbox in a GUI.
 55     //
 56     // It could also take a delegate object to do the display work, thus
 57     // improving runtime performance but that would be less flexible.  In this
 58     // particular programs case, just doing Console.WriteLine() itself would
 59     // be OK. See the foreach loop over tail() up in Main() for reference.
 60     //
 61     // This method also sucks up memory like a filthy whore because it stores
 62     // the whole file in memory as a IList<T>.  That’s fine for a quick and
 63     // dirty protype. In real life, this should use a string[] array of length
 64     // ‘n’ and only store that many lines. That way it could handle files 5
 65     // billion lines long just as efficently as files 5 lines long.
 66     //
 67     // I chose not to make that change in this example, in order to make the
 68     // code as simple to read as possible.
 69     //
 70     // Incremental development +  code review = good idea.
 71     //
 72     static IEnumerable<string> tail(int n, TextReader s) {
 73         string line;
 74         var list = new List<string>();
 75 
 76         try {
 77             while ((line = s.ReadLine()) != null) {
 78                 list.Add(line);
 79             }
 80         } catch (OutOfMemoryException) {
 81             die(ExitCode.Failure, “out of memory”);
 82         } catch (IOException) {
 83             die(ExitCode.Failure, “error reading from file”);
 84         }
 85 
 86         if (n > list.Count) {  // a smart bounds check!
 87             n = list.Count;
 88         }
 89 
 90         // implecations of a GetRange() using a shallow copy rather than a
 91         // deep copy, are left as an exercise to the reader.
 92         return list.GetRange(list.Count – n, n);
 93     }
 94 
 95     static void die(ExitCode e, string message) {
 96         Console.Error.WriteLine(“tail.exe: “ + message);
 97         Environment.Exit((int)e);
 98     }
 99 }
100 

This is a backtrace of the development process involved.
The program started simple: with the Main() method in Tail. The first thing I did was a simple check to see if args.Length was == 0, and exiting with a usage message. Then I remembered while writing the Console.WriteLine() calls for the usage message, that I really wanted (exactly) two arguments. That’s how the test became what’s written above in the code listing. A couple minutes later I moved the usage message code from inside that if statement to a usage() method. I did that to keep the Main() method more concise: unless you have reasons to groan over function call overhead, doing that is often a good idea. (Up to a point that is.)
From the get go, I knew I wanted the meat and potatoes to be in a method named tail() instead of Main(). For the same reasons that I created usage(). So that because a short using statement over a new StreamReader object.
First up was converting the string arg[0] from a string representation of a number, to an integeral representation of a number. At first I used uint (Unsigned Integer, 32-bit length) but later decided to make it plane int (Signed Integer, 32-bit length) because that’s what subscripts into a collection are defined in terms of. I don’t care if the user wants to display more than ~2,147,483,647 lines, it’s only an example program, damn it! Because tail() shouldn’t give a fuck about converting the programs argument vector to a type it can use (which obviously needs to be numeric), the caller (Main()) does the conversion. First tried args[0].ToUInt32() and when that compiled with errors, I hit Google. That gave me the System.Convert documentation on MSDN, from which it was easy to find the proper method. Because MSDN lists what exceptions System.Convert.ToInt32 can throw, and I know from experience that testing for such things is necessary ^_^, I quickly stubbed out catch clauses for FormatException and OverflowException. I wrote a simple set of messages to the standard output stream and an exit for each one. Than I converted them to using the standard error stream and wrote an enum called ErrorCodes, complete with casts to int when needed.

It was about this time, that I decided that implementing a simple method like Perls die() or BSDs err() would be convenient. Thus I implemented die() and replaced the repetitive error code. Functions are almost like a reusable template in that way. Then I decided that ExitCode was a better than for the enumeration than ErrorCodes, since it was being used more generally as an exit status (code) than an error report; unlike Microsoft I do not consider Success to be an error code ;). That was a simple global search and replace, or :%s/ErrorCodes/ExitCode/g in vim. Followed by a quick write (save) and recompile to test. Job done.

While I was at it, I also had an intentional bug encoded into the exception handlers for Convert, originally n variable was in a higher scope than the Convert (the using instead of try block). The error message for handling FormatException, used n.ToString() and the one for OverflowException used args[0]. The bug here was a subtle food for thought: one displays the result of the conversion, which might not match what the user supplied -> thus confusing the user. The other displayed what the user entered, which might not be what the program had tried to used. That also pushes an interesting thought on your stack, since the same data is used by both die()’s why do we have to write and maintain it twice? Alas, I realised the n variable was in too wide a scope and thus made that mind-play a moot point (by removing n from the scope of the catch statements). If you recall: using minimal scope for variables was actually the intent of the exercise, not error handling and code reuse.

Next I focused on implementing tail(). At first it was a simple. Just take a number and a StreamReader, and do a little loop over reading lines—for a quick test. When I checked the documentation on MSDN, I noticed that StreamReader was an implementation rather than a base class for TextReader. I always find that weird, but that’s outside the scope of this journal entry. Thus I made the using statement in Main() create a StreamReader and pass it to tail(), now taking a TextReader. Originally it also had a void return type, and simply printed out its data. I did that to make testing easier. The comments above make a sufficient explanation of why IEnumerable is used, and what I’ve already written about StreamReader/TextReader may suggest why it doesn’t return a straight string[] (e.g. array of strings).

The heart of it of course, is just feeding lines from a file into a generic List of strings. Since the exceptional possibilities are more straightforward, I wrote the catch blogs first. After that it is merely the question of extracting the correct lines from the tail end of the list. That’s a simple one to one (1:1) abstraction to how you might do it manually. I believe simple is the best way to make a prototype. Since the student in question was joking about how his implementation would likely crash if the line numbers were out of whack from what’s really in the file, I was sure to include a simple check. If the # of lines requested is greater than what really is there, just scale down. Volia. The comments at the top of the listing above, show why there is no error message displayed.

Extracting the items was a bit more of a question, my first implementation was a simple C-style for loop over the list using Console.WriteLine(). In the conversion to returning the data to be displaced, in which the tail() call in Main() became the above foreach loop. I added the comment about GetRange() more so as food for thought (from a code reuse and optimizational perspective). The math needed to extract the correct range of lines is trivial.

I then took a few moments to look at things over, doing a sort of code review. A few things were rearranged for clarity. I also introduced a bug, breaking the specification goals. If you look close enough at tail(), you will see that the variable line is only used inside the try block, yet it is declared at method scope. The #1 goal of the exercise was to avoid such things, hehe. I also thought about adjusting things to use an n sized cache of lines, rather than slurping the entire file in memory but decided against it. To keep the code easier to read, since the target-reader knows neather C# nor a lot of programming stuff, I just left comments noting that pro and contra of the matter.

Some people might find the method naming style odd for C#, but it’s one that I’ve come to like, thanks to Go and C#. I.e. publicly exposed functions get NamesLikeThis and those that ain’t, get namesLikeThis. Although personally I prefer C style names_like_this, aesthetically speaking.

The test file I used during the run was this:

line one
line two
line three
line four
line five

and most tests were done using various adjustments on:

terry@dixie$ gmcs tail.cs && mono tail.cs 2 test.txt

After sending the files over, I also whipped up a Visual Studio solution in MonoDevelop, and than realised that I left a rather unprofessional bug. If the filename in args[1] didn’t exist, the program would crash. That was easily fixed on the fly.

Overall the program took about an hour and a half to write. For such a simple program, that’s actually kind of a scar on my pride lol. But hey, I’ve barely written any code this month and I had to look up most of the system library calls in MSDN as I went along, I also tried to make it more polished than your typical example code. Which usually smells.

I can also think of a few ways to incrementally adopt that first exercise, into several other exercises. That might be useful.

Between Left 4 Dead versis and COD6: Modern Warfare 2 Team Tactical, I’m almost tempted to concentrate on competitve tactics again :-/.

I’ve been experimenting with window managers lately: fluxbox, openbox, awesome, and musca. Fluxbox and openbox, are pretty much just generic window managers, at least in my eyes. That said, they are well worth using, for most peopel. Awesome and Musca are tiling window managers, and a lot more, eh, minimalist. While I used to collect window managers, among quite a few other odds and ends back when I had time for it: but I have never done the “Tiling thing” beyond a very brief test drive of dwm.

Awesome and Musca create an interesting experience: you create the windows, the window manager, manages them. It’s almost alien lol. Normally you create a window, the window manager figures out where to draw it. You do the rest, e.g. by resizing and moving it around as necessary. In these tiling window managers however, newly created windows are automatically arranged and sized by dividing containers.

Launching your first window is like maximising, lauching a second window causes everything to resize and give each program half the screen, and so on based on some tiling pattern. The most used seems to be 1 half sized window left and 2 quarter sized windows right; works better than you might think. Rather than resizing the windows individual, you resize the containers. So if the screen is laid out as:



|         | term |
| Firefox |------|
|         | chat |


>

Selecting either the term or chat window and attempting to resize will resize all three windows. Try to enlarge the chat window horizontally, and Firefox will shrink and term grow, horizontally. Try to shrink the term window vertically and the chat window grows vertically, and so on.

It’s mind blowingly better than what the style of window management people are used to these days, which dates back to like Mac OS 2 or Mac OS 3 back in the ’80s. It is also a little bit awkward to let the computer take care of something, that you’ve been doing by hand for almost twenty years!

Relishing the experience however, has made me think of something different. I was just experimenting with the MinOverlapPlacementPenalties and MinOverlapPercentPlacementPenalties settings in FVWM, and it hit me. What if you could dynamically define what windows are important? I.e. what screen space should have more “Don’t cover this up unless necessary”, and how big a frame (i.e. for auto-tiling) should be, and so on?

It is technically possible, if perhaps computationally ‘interesting’ to figure out at the machine level. The windows that spend the most time focused or are most often gaining the focus, would be prime candidates. If the user ‘uses’ the window more than others, give it a larger chunk of available space scaled to its idea of how much space it needs, then prefer minimising the percentage of those windows being covered over or shrunken to absorb other windows in the same screen space.

It is food for thought!

Hmm, my mother is so deathly tired she walks in my room and asks me to make her something for lunch, a sandwich would be nice. Oh, and while I’m going to be in the kitchen anyway, could I fill her water and bring back her bag of potato chips?

Then she walks into the kitchen ahead of me to fiddle with the water bottles. She’s was also much to tired to take her potato chip back with her when waltzing out of the kitchen. By the time I’ve delivered her glass of water, she’s already gotten up again and walked to the kitchen. I go back to making the sandwich once she gets out of the way.

Somehow, I think everyone else in my family would have shouted, “Make your own ******** sandwich!” If you have strength enough for all that walking, odds are you can at least carry a several oz bag of potato chips with you, it’s not like lugging a 10lbs bag of Kartoffeln!

The Price of Obedience

Two weeks ago while looking for the house we were supposed to stop at, the car hit “Half a tank” on the fuel gauge before she decided to call for directions. To my mother, the half way mark is synonymous in her tiny mind with what happens in real life when you reach the empty mark.

Somewhere between three to five demands to “Go no further”, I reminded my mother that in America it is illegal to just stop the car in the middle of the road because you damn well please. In fact, as the driver: legally it would’ve been dependent upon my judgement whether or not there was any sudden obstacles ahead to warrant such action, not hers as passenger and owner of the car. It pays to read the fine print, right? Well, she wouldn’t stop demanding the car to be stopped. The way English works, her choice of words in fact ordering me to stop on the spot.

Since my mother apparently thought herself smarter than the law, the driver (me), FORD hardware, and GOD (who created physics); and after all, it is her car not mine. So I decided promptly to give my mother exactly what she was demanding of me `ad nauseam`. Checking to make sure there was no one behind, in between her orders to “Go no further”, I said “Fine”, and slammed the brakes—bringing the car from approximately 43 to 0 miles per hour in the machines absolute minimal stopping time. The kind of extreme breaking that normally, I would only use if the alternative was to hit a brick fucking wall.

Well, the car stopped so fast that you could smell the rubber burning and there was a lovely cloud of smoke to accompany the screeching sound of trying to stop a moving car so near instantaneously. If seat belts weren’t buckled or there was any cars behind, I wouldn’t have satisfied my mothers orders to the letter. I’m more responsible then that. As there was no threat, I obeyed to the letter: and went no further ;).

A week later (-2 days), just before the weekend the car started to make a metal on metal sound whenever using the breaks. I expected when I chose to obey, that the action of going no further would total the break pads: which were old. Quick thinking methodical bastard, yes I am. Maybe some people should just learn to think rationally before I have to teach them a lesson. In my experience, my family only understands two things: violence and money. Since I’m not willing to beat my mothers brains in, following her orders to the point of burning through old break pads sounds like a good idea.

It took about a day’s fearful stewing over it, for my mother to go from remarking that it was nobodies fault because the break pads are old and worn; she’s bitched about them getting worn out over the past couple years, and also absolved me of any blame for the breaks; damn I wish I had a hidden tape recorder. To instead, loudly cursing me the next day and wishing me to my face that I would “Drop dead and rot in hell”, among much worse things! I expected that would take an hour or two at most. Guess I was wrong.

Now after twenty two years of my mother, I know that being told to drop dead and rot in hell is about as close to a term of endearment as this family gets. It’s ceased to phase me a long time ago. Of course, if I ever showed any sign of being phased by it would be like putting blood in shark infested water. So I’ve learned to take her exponentially increasing hatred with a straight face, rather than risking her doubling her efforts. There’s a subtle joke in that for the math savy layman.

At first, I was actually tempted to tell her to “Be careful, I might aim to please” when I was told to die, but decided against it almost as fast as thinking of it. Reasons being that because of family history, that could be a potentiality painful remark to use on her, and obviously if I ever passed on before she did, liable to be remembered; which could also trigger her remembering the last time she was told “I aim to please” in the context of telling someone to up and die. I’m not as hurtful as my family. Sure, sometimes I’m an ass but before I open my mouth, I try to wager how much harm it will do. My mother by comparison skips thinking and lets her rage do the picking of words indiscriminately. I still remember some years ago, my mother mock-threatening to stick me with a fork, within earshot of someone who grew up with that. She just doesn’t THINK.

End result? Just over a we bit oer $100 spent on the lesson. The real question is, has she learned anything from it?

A/ Half a tank is not synonymous with out of gas.
B/ You’re not supposed to stop in the middle of the road for no reason.
C/ It’s the driver’s decision not the passengers.
D/ Being an irrational disrespectful bugger gets you no where with a geek.
E/ Be careful what you wish for, English is a very precise language.

Doubt ma has figured any of those out, but alas it does give her something to hate (me) with more focus than normal. Which will at least keep her mind off more serious ailments part of the time. An added benefit of deciding to obey that order to go no further: I’m hated worse than normal for a while, but it distracts her from worse.

I might also note that she almost never allows the car to go further than 20 miles from home, and on roads averaging a speed limit of 35mph to 45mph. That car can go up to 60 miles down the Interstate at an average speed of 70 miles per hour, and not even use up a third of a fuel tank.  When the “Go no further” incident occurred on Sunday, we were just outside walking distance of home and a few miles (or less) from a gas station. That means the chances of running out of gas would have been 0, unless she decided to take a trip to Alabama while we were out. I also bought gas that day, filling up to the mark below full, for $10.01. A full tank of gas for that car would cost about $40 going by the cars manual and average gas prices here.

I have no respect for displays of irrational fear, especially not from someone in their sixties. I’m also used to being automatically despised and loathed by people who should know better.

That’s life.