Tuesday, January 21, 2014

emacs windmove and Mavericks Terminal.app

I had trouble getting emacs' windmove mode working right under Mavericks' terminal app. It seems that the terminal app does not have a keyboard mapping for S-up and S-down. For posterity's sake, here is what I did.

First, I had to add these to terminal's keyboard map:

shift cursor up: \033[1;2A
shift cursor down: \033[1;2B

Then, in my init.el, I had to add:

(define-key input-decode-map "\e[1;2A" [S-up])

I'm sure there's got to be an easier way to do this, but this got me running.

Tuesday, April 27, 2010

F# weirdness of the day...

I have a piece of code that says:
    |> Seq.map (fun x -> x.GetAttributeValue ("href", "no url"))

Which I wanted to rewrite to "the other syntax" accepted by F#:
    |> Seq.map (fun x -> (x.GetAttributeValue "href" "no url"))

But I have no luck. The amusing thing is the error message I get from Visual Studio:
The member or object constructor 'GetAttributeValue' taking 2 arguments are not accessible from this code location. All accessible versions of method 'GetAttributeValue' take 2 arguments.
Say what?

[p.s. I posted this to Stack Overflow to in hopes of getting a bit of wisdom. Check there for possible answers.]

Getting all a hrefs from a webpage -- F# warm-ups

Been needing this for quite some time, and decided it was about time to tackle it as a way to flex my F# muscles a bit. I wanted to make this a command line utility, but haven't gotten around to it yet. If I do, I'll have it consume the html from STDIN, and spit the links to STDOUT. I want to do it that way to allow flexibility in how the pages are fetched.

Here is the code:

Thursday, April 15, 2010

Getting cron to play nice with me in cygwin

Our machines at work are currently running Win7, with cygwin. I've been a long time linux user, and have always enjoyed the composability of the command line tools.  I finally bit the bullet and decided to stop using Scheduled Tasks for a tool I'm more comfortable with: cron. Here is what it took to get all things working nice.

  • Install a MTA of your choice.  I did not want to deal with trying to setup qmail, sendmail or any other of the big tools for a machine that only needs to relay mail out.  I looked at nullmailer, ssmtp, and msmtp.  Ended up installing msmtp.  We use google apps for our mail needs, so I configured msmtp to work with it.  Here is my ~/.msmtprc config:

logfile ~/.msmtp.log

account gmail
host smtp.gmail.com
port 587
auth on
user @
password *****
tls on
from @
tls_certcheck off

account default : gmail

  • Make sure that the MTA is working.  You might need to run msmtp-config to set things up, such as repointing /usr/sbin/sendmail to /usr/bin/msmtp.  As you can see, I turned off tls_certcheck.  I could not figure out, in the time I had, how to get certs into my machine.  Seems that openSSL doesn't install them anymore.  Might want to make sure that you "chmod 600" that config file to prevent your password from getting out.
  • Install cron.  As a user with right to intall services on your machine, run "cron-config".  That should take care of things.
  • Create a crontab.  Here is a very simple one I created.  It's nice to have it send me email with the output.  Read up on cron if you don't want that feature.  This file lives in: /var/cron/tabs/


# 0-59  0-23    1-31    1-12    0-6     cmd
# min   hour    DoM     mon     DoW     cmd

# silly test
 */5      *       *       *       *       date

That's all folks! Hope this helps someone out there.

Monday, April 12, 2010

OO's N-levels of indirection

OO relly frustrates the daylights out of me sometimes.  You find a function that gets passed an IThing, which has referectes to other IThingies.  In working with some code, you find there there is a call to an IThing.IThingy.Foo, and you try to determine which piece of code is responsible for it.  Good luck.

This anoying trip ussually starts with trying to figure out what classes implement which interfaces,  something that VS2010 still doesn't seem to make trivial (maybe my Kung fu is just not strong).  Trusty Reflector to the rescue.  If you are lucky, there is only one implementor, and this journey is over.  If you are not lucky, you get to try to traverse the call stack, to see which implementation got instantiated and passed to the function at hand.  If your are completely unlucky, there is a dynamic (i.e. reflection) call somewhere in there, at which point your brain segfaults.

Thursday, April 1, 2010

Echo and Process from cmdline

Here is a quick one for the sys admin tasks. I want to execute a command, and based on the output, not the exit code, execute something else. At the same time, I want to see the output of the original program displayed on the screen. The following does not work because grep swallows the input.

$ cmd | grep 'pattern to find' && doSomething

My current solution is not optimal, me thinks, but at least it lets me see what the original output is. Here is what I have:

$ cmd | tee /dev/stderr | grep -q 'pattern to find' && doSomething

Got any other way to do this?

P.D. I hate blogger's formatting...

Tuesday, June 9, 2009

Ouch: Bashing the "right thing"

Finally got around to reading Worse is Better by D. Gabriel. I must admit, I feel I'm more of a "right thing" kind of guy, but I can see what Gabriel's point is. It seems to be a variation on "the perfect is the enemy of the good" (Voltaire, me thinks). I specially liked the idea that trying to design a system that has all the correct interface leads to a system that rarely sees the light of day. The implementation is just a nightmare for these 100% perfect interface systems.

I've know for a while now that the kind of compromises that this paper brings to light are hard for me to swallow. Probably the reason why I think I'd much rather do science than engineering. Darn, I want simplest and complete interface, AND simplest and efficient implementation.

On thought that came to my mind as I read the paper was: is Haskell trying to be the "right thing"? What do you think?