Run!

I haven’t posted about my running in a long time. Mostly because, I have been doing the usual. Built back up to 20 miles a week, and just kept running.

About two and half months ago I started training for a spring marathon. I didn’t really want to post anything about it till I was well into the training plan, lest I get hurt again.

Well, as of yesterday I feel like I am deep into the plan.

Hath and I drove down to Lebanon PA to hit the rail trial there. There is a pretty nice parking lot near the Twin Kiss that is along the Rail Trail. From there we were able to run 4 miles out toward Conewago, and in fact actually ran about 100 yards into Conewago. We turned around there, and ran back to the car where we fueled up and belted up and then took off 4 miles up the mountain.

On the way back down around mile 13 I started feeling a little ill. I felt tired and shaky. Hath, astutely reminded me that I could pop another gel. I don’t know if it was psychological or not but I felt pretty good pretty fast after that.

I still have about 2 and half months till the ‘thon, but I am feeling strong, and looking forward to more miles.

recap:

Miles: 16.33
Calories: 2,426
Time: 02:51:14
Connect Link

local pkg server not starting

I installed OpenSolaris on my laptop this week, and have found it to be quite usable.

I was poking around on opensolaris.org and ran across documentation for making packages for the IPS system.

In particular, I found this Hello World of package rolling. Except that…it doesn’t really work. And if you are a Linux guy on OpenSolaris, you might be scratching your head with how to fix it. After googleing around and reading a few man pages the fix turns out to be simple.

The first few commands they want you to run are

And those will complete without feedback, however when you actually go to use that repo later, you will find it not there.

Looking at svcs shows us it’s in maintenance mode:

That’s no good, it should say online. So pop open the log and have a look:

You will see something like:

The take away here is the publisher.prefix jazz. Gotta have that, or else the service won’t start. Easy fix:

Finally:

That should do the trick.

If you decide to go ahead with trying to build Midnight Commander, there will be other problems with the include file, but you will see what they are and be able to sort them out. After I got this figure out, it was pretty simple to see what else was wrong simply by trying to complete the steps.

Upgrading the PAP2T ATA

A short while ago my girlfriend and I ported our home land line number over to our sip terminator. I have had a Linksys PAP2T Analog Telephone Adapter (ATA) for some time, but mostly used it as a lab device for mucking around.

When we made the switch to full time sip, I started using the ATA as the main extension for the inbound ported number.

One thing I found that I didn’t care for was the ring cadence. It doesn’t sound like a typical North American ring that my North American ears are used to, so I set out to figure out how to change that.

After poking around in the web interface of the ATA a bit, and googling about, I noticed the interface didn’t contain inputs that others were claiming to have changed. I figured I needed a firmware upgrade, and I was right. According to Wikipedia

As of 8/21/09 the latest PAP2T firmware is 5.1.6 released 11/21/2007.

I was running Firmware Version: 3.1.15(LS) . Heh, so a little out of date.

Upgrading was simple, however I followed a really long route to get there.

First thing is to grab the lastest firmware from Cisco, and place it on an available web server (or tftp for that matter).

Then log into the web ui of the PAP2T, and click the (switch to advanced view) link, and then click the Provisioning tab at the top.

Find the dialog box for Firmware Upgrading, and set Upgrade Enable to Yes and then set the upgrade rule like I have it here, but using your ip/domain and path for the file:

The (<5.1.6)? portion of the rule tells the PAP2T to not download the firmware unless it’s running an earlier version than that. The rest of the rule is simply the protocol and path to get the file (you can also use tftp if you desire, just change the protocol to tftp://)

Then unplug the ATA and let it come back up. Since this was on my lan, it took less than 10 seconds to come back up and be usable with the new firmware.

After all that, log back into the web ui, confirm the upgrade, navigate again to the Advanced View, then the Regional tab, and finally, change the Ring Waveform from Trapezoid to Sinusoid, and Save Settings one last time.

Violin! You should now have an approximation of the North American ring.

Happy hacking!

Resources:

  1. Cisco Product Page
  2. Latest firmware
  3. voip-info page

euler 3

As some of you may know I have been attempting to learn Clojure. To that end, I thought it might be a good idea to learn by solving the Euler Problems.

After tackling the first one in shell with almost zero trouble, and then finding info on how I wanted to solve the second one with little fuss, I was pleasantly surprised to find that the 3rd problem was a little more difficult.

I am not a math guru. I avoided math in school like it was giving away beatings.

As someone in the technology field it really hasn’t impacted me as much as parents would like you to believe, but it does make this challenging.

The goal was to find the largest prime factor of a rather large number (600851475143).

If you are anything like me, your first instinct is to mow this over with sheer will power. And so you will attempt to find all the factors of N, and then filter them.

However with a number this large, your first instinct will be wrong.

This C++ took around 65 minutes (on a 2Ghz Core 2 Duo) to run (and that’s just getting all the factors):

(I did it in C, so it would be as fast as I was capable of coding)

Then I read a boatload of math web sites and asked a lot of questions of folks on irc, till I got it in my head that by finding the smallest factor of a number, you could limit the data set to something more manageable.

So this morning I finally sat down and wrote out working clojure code

I am pretty happy with this, though I have already had people point out some optimizations I can make. But overall, I think as far as understanding the problem, and coming up with a reasonable solution in a functional way, I am pleased.

Then, as has been my MO lately, I started thinking about the problem in shell. And I really wanted to write code that would fit in a tweet, but I kind of got tired of thinking about it, and decided this is good enough.

So that’s that. I will probably read about optimizations for the code, but that was my best effort.

Happy Hacking!

Bleh

My ankle is getting better all the time, but it’s still not runnable.

Potentially next week I could think about a short run.

It’s not looking good for Harrisburg this year.

I don’t even feel like talking about it.

Update!

Good news first.

It’s not broken…whew! I was really worried. I was worried I’d have to get surgery (something I have an irrational fear of). I was worried I’d have to get a cast, I was worried. Period.

Alas, no. It’s a wicked bad sprain, and an even more wicked hematoma.

I am not sure as of yet what this means for my marathon plans. I suppose only time will tell. I do still plan to line up in November, so we’ll see.

Tonights nasty pic of the day

Well Crap.

There I was 1.1 miles into a 4 miler tonight when my foot came down crooked and rolled under me.

I heard/felt a pop as I went down like a sniper took me out.

My first reaction was to roll out of it and grab my ankle to assess the damage. All I could think about was the marathon and how long I might be out if this were a break. Luckily it felt fine, I grabbed all around and poked and prodded.

Then it started to swell, and by started I mean it went from looking puffy to looking like my body was falling apart inside and pooling up on the side of my ankle.

A woman and her son came running up to me. Luckily it looked like my ankle was destroyed and there was blood from my knees oozing everywhere, or that would have been embarrassing. :)

Since I was a mile from my car on the trail, the woman prepared to carry me out. And I think she intended to do it. But, I told her that I had a good 80 pounds on her and that it was probably best if we flagged down a golf cart. She agreed, but I really think she would have tried. Then another man and woman came on the scene, and the man went to get help.

Then a man in a golf cart brought the man back and I lumbered into the cart. The man took me to my car, where I hobbled around and drove home.

Laying on the floor in our living room, I called Shelly and asked her to come home from her mom’s to help me…heh, that sucked, but it was super hard to get around.

So, after consulting my doctor on IRC…since it wasn’t bruising we have decided to wait upon the morn to see what happens.

Bleh.

Not for the squeamish (I say that because I hate looking at crap like this) :
TPIWWP

As long as it’s not broken, and I don’t think it is, I am pretty sure I can still make Harrisburg.

Reading/Printing a file

A friend of mine at work, also bitten by the functional bug, has been hacking on some Scala.

He showed me some code yesterday and I thought it might be fun to convert it. I am not going to post his code, as that would be presumptuous, but I have mine to show.

The goal is to read up a file, and then print that file prepending each line with the number of characters in that line, as well as padding the beginning so that everything lines up.

The usual caveats about my newbness.

; Get the name of the document from the cli
(def arg (first *command-line-args*))

; Convert the doc to a vector
(def lines (vec (.split (slurp arg) "\n")))

; Takes a string, and finds out how long
; the length, of the length is
(defn length-of-length[s]
(.length (str (.length s))))

; Returns the longest element from a collection
(defn get-longest-line[lines]
(reduce (fn [x y]
(if (>(.length x)(.length y))
x y))lines))

; Repeat s string t times.
(defn pad[s t]
(take t (repeat s)))

; Find the maximum width of a line from the doc
(def max-width (length-of-length (get-longest-line lines)))

; Take the vector of the file, iterate over the lines and
; print each one prepended with the number of characters that
; appear in that line
(doseq [line lines]
(let [num-spaces (- max-width (length-of-length line))]
(println (apply str " " (pad " " num-spaces)) (.length line) " | " line)))

Tip of the hat to ‘Chousuke’ in #clojure for the clue on ‘apply’.

Example


$ java -cp /opt/clojure/clojure.jar clojure.main scala.clj test.txt
50 | This is a text file with lines that vary in length
0 |
13 | ^^ Blank line
34 | Some other text that is mid length
9 | Oh hai!!!

Thanks for playing!

Dwarf Name Generator

The local ruby group sends out the Ruby Quiz (with some regularity). This week it was to create a Dwarf Name Generator.

I thought of a fairly simple solution in Clojure pretty quickly, but then it took me a while to implement it. Anyway, here is what I came up with.


; Create a couple of Maps with keys being Integers
(def firstnames {1 "Danby" 2 "Tamreil" 3 "Vash" 4 "Gobu"})
(def lastnames {1 "Dongledorp" 2 "Floopydoo" 3 "Goran" 4 "Zypher"})

; Return a random Integer with a value > 0 but < = the upper bounds
(defn randomize [upper]
(let [randy (. Math round(* (. Math random) upper))]
(if (= randy 0)
(int (+ 1 randy))
(int randy))))

; Since Maps, can be used as Functions that take a key as an argument
; pass those to println
(println (firstnames (randomize (.size firstnames))) (lastnames (randomize (.size lastnames))))

The reason it took me so long is that initially I wasn't casting 'randy' to a Java Integer, and using it as a argument to a Map (which causes the Map to act as a function) was causing the Map to not find it while looking it up. After a bit of head scratching, I asked in #clojure.

Obviously, if I were a linguist, I would have created a lot of maps with just parts of names in them (I am sure that is called something), and then randomized that further, but I am not, and since the underlying mechanics would be more or less the same, I left it as is.

Happy hacking!

Clojure/Java Interop

Hello again.

I picked up the book Programming Clojure and have made my way through the first two chapters which were great.

Last night I started the 3rd chapter, on Java Interoperability.

I was hoping to toss together a single Java class that I could then try to rewrite in Clojure to help me learn. Following is what I came up with. (Note, I am not a Java ninja by any stretch so beware).

This is not intended as any sort of comparison of the languages per se. It’s simply, “Given X, I had to do Y to get the same functionality”.

My idea was to find a Java library for parsing rss and then parse out the rss for this site, prining the Title of the Post, as well as the link (this is the lieberry I used).

First the Java:

And next the Clojure:

While I am not sure the Clojure code is as succinct as it could be since I am still pretty new, I do like the looks of it. I agree with the notion that it’s an expressive language, and that one can do quite a bit with a minimum of fuss. I think that practically the syntax is idiomatic, I am not entirely sold on the dot form, and dot dot macro. I don’t think they are as visually appealing as would be a symbol in this context. But they do make sense.

Happy learning!

Next Page »