Sunday, April 5, 2009

Emacs Macro & ssh

Recently, I've been trying to customize emacs to do more and more stuff for me that I find tedious.

One of those things is setting up the ssh sessions that I use all the time. Often, it is nice to have them in an emacs session (although sometimes it's a pain, like when you want to run emacs in that session)

Multi-session does a pretty good job, but I was still having to connect to where I wanted to go and then rename the session to reflect where I was (i.e. work, live, etc)

I spent a bit of time one day making a macro for emacs lisp which did everything I really needed (warning, this requires multi-term.el to be loaded)


(defmacro defterm (termname &rest body)
(let ((mytermname (concatenate 'string
"term-" termname))
(intertermname (concatenate 'string
"*" termname "*")))
`(defun ,(intern mytermname) ()
(interactive)
(if (get-buffer ,mytermname)
(switch-to-buffer ,mytermname)
(progn
(make-term ,@(cons termname body))
(switch-to-buffer ,intertermname)
(rename-buffer ,mytermname)
(term-char-mode)
(multi-term-handle-close))))))



After this I can use the same arguments as you would for make-term, except that the first argument is the name of the terminal. So, for example, if I wanted to log into a remote server and then log into another remote server that is behind the firewall, I would call it like so:

(defterm "brutus"
"ssh" nil "-t"
"kelly@servera.somewhere.net"
"ssh" "-t"
"kelly@brutus.somewhere.net")


This would create function term-brutus that would create a buffer called term-brutus that was logged into the remote machine, or it would find that buffer if it already existed.

If you have a bunch of these, and want to do them all at the same time without
having to call each separately:


. . .
(defterm "bash" "bash" nil)
(defun start-terms ()
(interactive)
(term-greywolf)
(term-live)
(term-postgres)
(term-bash))



As a side note, I discovered while working with this that you can chain your ssh calls in this manner

ssh -t kpm@servera.somewhere.net ssh -t kpm@serverb.somewhere.net

and this would log in to the first machine, call ssh to the second machine and that's what you wanted in the first place. (don't ask about port forwarding doing this, I haven't tried it.)

Hope this helps someone.

Tuesday, February 10, 2009

How To Write Parallel Programs

Notes from How to write Parallel Programs: A First Course

How To Write Parallel Programs
How To Write Parallel Programs
- Nicholas Carriero & David Gelernter

Why did I read this book?

Cpu counts are going up, and the way we write software is gonna change - take a look at The free lunch is over . While that was penned three (four?) years ago, the way we really design software (if you are not a video game developer or something) hasn't changed all that much.

This is going to have to change eventually if we want our software to ever use the computing power that really is out there. What are we gonna do? Well as the above article points out, guys like me are gonna have to change how they think about implementing software. So ...

I read a really short review somewhere and I had to get the book.

Parallel programming

The book talks about a coordination language called Linda, which looks like to me as if it was cooked up in Lisp. The basic idea behind Linda is that you have this database called a tuple store (or space), and you have all processes interact by means of this database.

There are only a few commands and you can 'search' the database using variables as you would in prolog.

example:

in("test", 1, ?x)

so that would find a tuple of length 3 in the database and it would match any tuple with "test" in the first position and 1 in the second and whatever in the third. If it can't find anything, the default behavior is to block as we are expecting for it to turn up at some point.

Another method is to insert something in the tuple store:

out("test", 1, 1)

The third method is eval. Eval basically starts a new thread (in some implementations, groups of threads) and it eventually adds the tuple into the space:

eval("test", 1, somefunction(x))

so this would go run a new thread, evaluate somefunction in that thread and put the tuple in the store. This will not bock the parent.

There are other operators, but these are the three main ones. It is not intended to be a full language, just a 'bolt on' to an existing one.

That's it.

Basic paradigms when writing parallel programs

The book used the metaphor of a house and how you would sequence the workers to work on the house.

Result

Here you take every part of a house by section and you would assign a worker to one section, no matter what might be involved. For example, you might assign a worker a 'bedroom' and the worker would do everything for the bedroom, including framing, the wiring, the carpet, everything.

This would possibly run into problems because any workers given simple jobs might get done before the ones with complex jobs (i.e. kitchen, bathroom) and then you would have workers just sitting around.

Specialist

Here you would build a house like we typically do, that is you would have the plumber do the plumbing, the carpenter do the framing, the guy with the big whopping machines dig out the basement. etc.

Of course here you have the problem (assuming you only want to build one house) that you have a all the roofers waiting around on the guys with the big whopping machines and the carpenters. (ok the metaphor breaks down)

Agenda

Here you have all the workers line up and dish out the next thing that needs to be done. If you are building a foundation, you can have all the workers line up and bring a block to the building, apply mortar and then go back and do the next thing. Each worker will need to be told precisely what to do and it assumes all workers are equally adept at doing all the jobs.

Model substitution

According to the book, (at least in the software world) if one model fits the problem domain right, but is inefficient, we can (and this was important) substitute any of the methods for any of the others. We do this to fit the run-time environment that we are actually operating in, whatever is the most efficient. ( the book goes through several examples)

Granularity knobs

Another important point in the book is that each run-time environment is different from the next. We may actually be running on a one-processor computer, or we may be trying to solve on a supercomputer with a gazillion cores. The run-time dynamics of each system is going to vary by quite a bit. The book shows several examples where we may only use a fraction of the resources for certain parts of the problem, but could use more than we have for other parts of the problem.

To address the situation, they suggest granularity knobs, or regulating how much each subprocess could do at once, and ideally make this a dynamic property during execution. To use our house analogy, you might make more progress if each person brings 3 blocks to the house instead of one, but you might not make much progress at all if you make them bring 1000 blocks at a time.

Wrapping it up

This was an interesting book (available online btw) that helped to think about parallel programming. It would be interesting to try to write Linda in Lisp (or clojure?). It would also be interesting to also try some functional methods to parallel programming (haskell comes to mind), and compare them to the actor model that is presented in the erlang book. Each one of them should be able to implement the ideas contained in this book, if not Linda itself.

Saturday, January 24, 2009

Instead Of Education


InsteadOfEducation



John Holt - Instead of Education


Recently while watching and listening to some of the works of Alan Kay I ran across a reading list that he put together. I really wish that Mr. Kay would write a book, but I'm also a fan of reading lists.

I actually had some of the books that were on the list, and I was familiar with others. I went to the library and grabbed a stack of the books. This is the first one that I read - I only spent a limited amount of time on the book, less than 24 hours from picking it up at the library to blog post.

Overview

The basic point of Holt's book is that people in general learn better when they are working on something that they want to do. Traditional schools squelch the natural learning that happens with children and that we should move away from compulsory education. He advocates a completely free approach to education as exemplified by the Ny Lilleskole in Denmark. This type of education has come to be called 'unschooling'

Ny Lilleskole - Denmark video

Mr. Holt presents two competing views of education. The first is a 'school' with basically no rules. Children are allowed to do what they want, when they want, and with whom they want. This is allowed to go on day after day after day. No suggestions about 'you should do math', and really no requirement that they attend. If the kids want to spend all day playing soccer, no problem.

He spends only a chapter talking about this school (Ch. 11), but goes to pains to point out that the students, upon leaving, usually go on to some form of 'traditional' higher education, and do better than their peers who were schooled in the traditional fashion.

Traditional School

On the flip side, he presents traditional school as a place that is oppressive and exists only to teach kids to respect authority, and be ranked in a pecking order. He says it all more eloquently than I am here but this is his basic understanding of the function of traditional schools. This constant compulsion, ranking and pigeonholing conditions kids to think of themselves in a certain way, and he spends a whole chapter (15 - Obedient Torturers) showing that people respond in a conditioned way to a figure of authority who 'knows better than I do.' - If I recall, John Gatto's book Dumbing us Down makes the same points as he does in chapter 14.

My Thoughts

My thoughts at first are "Hey! you can't do that!!" I wonder how on earth you get a kid to learn math if you don't force them to do anything, and I wonder why a smart guy would put a book like this on his reading list. Alan Kay, however, learned to read before the age of three1. Because he started learning from a young age, he learned quite a bit on his own, because he wanted to. Because of this early start as a self-educator, he had problems 'adjusting' to a traditional school format.

Here recently, I've been struggling to get my son to do his math. He complains that he doesn't like it and that it is boring. I tell him that he'd better get used to it because it's life.

I notice at my own work that I am so much more efficient and learn so much more when I am doing something that I want to do and I find interesting. I also know what it feels like when I am doing things that feel useless and boring, but someone else wants me to do, and I feel compelled to do them.

Is school primarily to prepare us for the latter? Would we be better served to have the former as our primary way of being in the world? Are we really preparing students for 'the world' to 'make' them learn things they don't want to?

Why is it that Ny Lilleskole worked when logic would say that it would not? Here is my guess. Kids are conditioned to think about themselves in a certain way. At a regular school, you are ranked at how well you do at rote memorization, how well you do what others want you to do, not how well you perform at doing what you want to do. If someone is telling you all day, every day what you have to do, then when you have free time, you don't really want to do anything.

Contrast the free school. Kids are conditioned to the idea that they are able to do whatever they set their minds to. At first the effect would might be a drop on standards achievement tests (of course they don't use those at the free school). Over the long term though, the underlying notion that I can do whatever I set my mind on doing would be the overriding learning from this environment. When the student gets into a college it is because it is their choice and they have in their mind that they can do it . . . or something to that effect.

Have you had any experience with unschooling? Let me know how it worked, what things we would all find surprising.

1. From the book Out of Their Minds: The Lives and Discoveries of 15 Great Computer Scientists. 1995

Wednesday, January 21, 2009

Social Media problems

My wife is working on becoming a midwife (almost there!) and I am interested in midwives and the problems they face and if there might be software solutions to those problems.

I searched twitter midwife I got what you would expect - twitters about women going to their midwives and looking for one and birth stories, etc. The example above works really great when you have a very narrow clearly defined search that you want to connect to. Searching for qooxdoo might get you 1 hit per day. In my search for midwives, I found 100's, but only one (future) midwife.

Assuming I did get a list of midwives, and I started following them - why would they be interested in following my stream of consciousness about javascript, python, things the kids said, and whatever else I'm doing, which brings me to one concern that I have about social media.

  • Problem one:

    Everyone lives in a number of worlds, I am a husband, father, programmer, etc. and I would suspect that those who care what funny thing my kids said wouldn't care at all about some javascript, python or lisp thing that I'm working on and vise-versa.

    This is most likely a generation gap question, I would suppose that most that use social media on a regular basis have very little problem having everything from every corner of their life (and from their ) all in one place. The idea that we separate work from family (or any other of our ) and that these are two separate dimensions is a concept from a previous generation.

  • Problem two:

    how do you keep up with everyones postings? Some might be really interesting, but lets say you are approaching it from a marketing or information gathering perspective as @fjakobs did? Not only do I worry that people may not be interested in what I am saying, I worry about finding what other people are saying and managing all of the stuff that comes through.

    I think the simple answer is that you don't. You don't try to manage the though process going either in or out (well, within reason . . .) - if you catch it you catch it, if you don't you don't if you find that someone is carrying on too much about stuff you aren't interested in, you can always quit following (unless it's your mom!).

  • Problem three:

    Twitter, FaceBook, Tumblr, blogs - wow there are so many things out there. People must find a way to manage their connections. When I post, it would be nice to have it automatically post to my twitter account with the headline and a tinyurl, and facebook (not that I have account) and whatever else I want. (then again see This Post

So, what other problems do you have with social media? How do you deal with these problems and more??

Let me know!

Why Social Media

I learned an important lesson over the last few days about social media. It all started with a bit of curiosity.

On the surface, it would appear that social media is all about connecting with those that you know. I look at my wife's Facebook page and I don't feel like I get it. I mean I understand the pictures and the updates on what everyone is doing and all, but the sea gardens and that stuff - not for me! She uses it mostly for chatting with people she knows and is able to connect with friends and family from all over.

While social media allows you to connect with family and friends, it also allows you to connect with people that you do not know based around a very narrow topic.

Starting with social media is intimidating -- At first it feels really stupid writing twitters about stuff - especially when no one is following you. I was twittering about stuff the kids had said, stuff I was doing, and once I twittered about a thought I had about the javascript framework qooxdoo .

A few hours later, someone from Germany (@fjakobs) was following me. Why was he interested in anything that I had to say? - It turns out that he was a developer working on the qooxdoo framework, and he wanted to be able to communicate with people who are using his framework.

To keep up on anyone that was interested in qooxdoo, he went to twitter search and created a RSS feed for qooxdoo. Not all that many posts, easy to keep up on and he got a list of anyone who wrote anything about qooxdoo. Now I know about @fjajobs and I can follow his progress on the things that are happening with this javascript framework, which is important to me.

This simple exchange helped me to understand social media in a way that I previously had not.

So, I have a simple question, what uses of social media am I still missing? What was your (twitter,tumblr,blog,...) aha moment?

Thursday, January 15, 2009

Hutspot

I had another blog that was focused on a computer language (lisp), but so much of what I do is not lisp that I wanted a spot where I could just blog about whatever I happened to be interested in at the time, not just one topic.
All of the successful blogs focus on one topic - I guess I'm too eclectic for that!