Monday, June 22, 2009

Support & Open Source

My love/hate relationship with my Dell Mini 12 continues.

On the love side, every time I see folks with other laptops, I think to myself, my God that thing is huge and smugly congratulate myself on my tiny machine.

On the hate side, Dell's proprietary crap makes this thing a PITA on Ubuntu (wireless driver + graphics card). This was mostly fixed by Jaunty, which basically just works on the mini-12 (to get the graphics card fully supported you just have to enable the ubuntu-mobile ppa). However, the problem with relying on a PPA etc is that everything is a bit more fragile. So, for example, when Ubuntu recently pushed a kernel upgrade (-> 2.26.28-13), the graphics broke. Of course, Ubuntu keeps your old kernel around after an upgrade just in case your system gets hosed, so I was able to boot from the old kernel with working graphics, but suddenly the wireless network card wasn't being recognized by the old kernel.

All of this was very sad: I was left with either a working network card or a working graphics driver. On the assumption that it would be a while before the graphics driver was fixed, I wasted a good hour trying to get wireless working again with my old kernel (networking requires a non-free driver, but it had just worked with ubuntu on the initial install).

Tonight I decided I'd rather have ugly graphics than no wireless and went back to the new kernel. While at it, I decided to drop into the ubuntu IRC channels to see what I could find. I went to #ubuntu-mobile, explained my situation, and left the window there while working. Within a half hour or so, the packager of the ubuntu-mobile PPA was talking to me. I was able to give him a useful error message that instantly told him what the bug was. He released a new version of the graphics module that fixed the bug, I installed, rebooted, and confirmed it worked.

This was quite cool. Within 1/2 hour of looking for help through online chat, I found the developer of the software that had broken. Within an hour the problem was fixed, not just for me, but for all users.

Here's what I'm thinking: this is why open-source development works. This is what's so cool about linux. I remember stories of my mother making similar breakthroughs with Microsoft support when she'd found easily reproducible bugs in Excel graphs -- only in her case she got a 8-step workaround to the bug and no fix. With open-source package management tools, it's easy to push updates out to all users fast, so a problem like this can be fixed right away.

Here's the problem, though: my solution wouldn't have been remotely possible if I was still using the version of ubuntu Dell installed. Dell has no one in their phone support team who could be nearly this helpful, and most likely has no one in its support system who could access someone this helpful. It strikes me that when companies think about using linux, they should think about harnessing the power of the linux user and developer communities as well. In short, maybe they should simply try to hire this guy to maintain a package archive for them that will make their hardware work with vanilla ubuntu. It seems it might work better than their home-rolled distro anyway, and it would certainly be better supported.

Tuesday, June 16, 2009

Simple scripting tasks

This afternoon Katharine asked me to do a very simple task. She needed to create a certain number of random groups from a population of students. The groups weren't purely random -- rather, they had to ensure an even distribution by grade level and gender.

Our student database is all in an online database, which, allows you to export data from it in a reasonably sane way. My approach to solving her task, which took 10-15 minutes to do, was as follows (I'll give the physical equivalent of each step):

1. Make an index card with each kid's name, class, and gender on it (export a CSV file)
2. Divide those cards into piles by grade level
3. Divide those piles into a male pile and female pile
4. Shuffle the decks of cards
5. "Deal" from each deck of cards into one "hand" per group needed.

I'm quite confident most people could come up with the algorithm above -- no programming skills needed. But, in our world, it's still not possible for most people to do the above programmatically. The physical solution is available, of course, but it's not repeatable, and it doesn't scale up well (the beauty of the program is it is equally easy to run for virtually any number of kids, groups, and factors you need to divide by).

My solution was roughly 50 lines of code, though it could have been much shorter. It strikes me that essentially this kind of data management is a large part of what computers are useful for -- whether it be converting one kind of table into another kind of table, or iterating over data to create things. Programs like Excel and tools like mail merge offer some of this power, but they usually fall short at some point[1].

So my question is, is a tool that would put this kind of programming into the reach of non-programmers conceivable? Available? In the works somewhere? I've often thought that a desktop-wide macro recorder would be enormously useful[2] but I'm not sure that's really what I'd want. Perhaps AppleScript gets at this, but I'm not sure that does what I want.

Here's an initial list of features that such a language or tool would need to allow:
  1. Easy access to data in rows, regardless or source, and easy export of data in rows, regardless of needed format.
  2. Easy actions on data in rows
  3. Easy filtering of data.
  4. Simple string operations, search operations, etc., to turn one form of data into another.
  5. Calculations and comparisons.
  6. Shuffling, randomizing, etc.
  7. Graphical interface or other tool that makes syntax errors an impossibility and make semantic errors difficult to make. Recording macros, for example, it is impossible to make a syntax error.
I realize this may be a completely insane idea. Perhaps people who think like me (and therefore want this tool) are already programmers (and therefore don't need it). Still, I have to think there's a population of computer users who can see what makes for an automatable task but simply lacks the tools to do it.

I also have to think that given the variety of ways that data presents itself, and the ways in which people regularly need to move data between one application and another, there are many tasks that can't be anticipated by programmers of any given application, but could be automated given the right environment.

[1]In this example, they fall short in a number of places. I've had them fail at much simpler tasks though -- I wanted Excel, for example, to look at a numeric grade and give me a letter grade. Because of the limited syntax of Excel functions, the obvious solution was to use nested if statements, but it limits the number of nested function calls at 7 -- alas, I had more than 7 grades (A,A-,B+,B,B-,C+,C,C-,D,F)

[2] Growing up, I had such a tool in a very early Mac OS and found it incredibly useful). But macros can't introduce elements like randomness or even simple calculations (unless you get very clever). Trying to imagine a macro language becoming powerful for basic scripting, I'd have to suddenly imagine GUI equivalents to powerful programming and commandline tools like the random library, grep, sed, and awk, and on and on. One enticing possibility is building on something like the firefox macro extension (imacros) -- given the diversity of webpages and webapps out there, nearly everything becomes possible via macros on the web.

Friday, June 12, 2009

Here's another update on Grace's consonants. I recently confirmed that she really is using a uvular trill for a "k" (actually, realized that she seems to have two separate sounds for the "k" sounds in English, neither of them standard, but one of them is definitely a trill).
It's so much fun!

Grace's sound, roughly

Phonemes she uses the sound for (in rough "English-y" notation)

/t/ and /d/

/b/ and /p/
d (back a bit)

/k/ (in "car"). We sometimes think we hear a proper "k" here but we're pretty sure it's a "d" variant, a bit like the "d" in an Indian accent.

/p/ in a whispered tractor sound and sometimes in "papa" (grampa). We debate whether this is a "p" or a "b", it may be an unaspirated "p" (and sometimes she whispers the whole word in an attempt at aspirating her "p"?)


fricatives & approximants

ʒ (zh)

/s/, /z/ /ʃ/ (sh),/tʃ/ (ch) /dʒ/ (j)
w (some version of it)

/ɹ/ (r) and /w/ - as in "wawa ("flower" or "water")

θ (th)

/s/ (word-terminal only) - as in "bus"

x? ʃ?

/tʃ/ (ch) (word-terminal only) - as in "beach"

Trills & funny sounds
[R] (uvular trill)

Used for the "back" K, as in "quack" and "chloe")
[ʙ] (bilabial trill)

Used joyfully and frequently for silliness
r̼ (linguolabial trill)

Used joyfully and spitfully for silliness

Thursday, June 11, 2009

User creation script

A consultant recently asked me for a copy of a script I created for our school to automate user creation. I thought it would be more useful for myself and the world if I just archived it here where I can always find it, and where other folks can use it (I find it much harder generally to find usable sample window code &c. than I do with linux).

These are my first (and hopefully last) scripts in virtual basic scripting. I'm putting them here to make it easier to share them, but these haven't really been prepared properly for sharing (I was simply working from examples until these worked). Obviously it would be worth setting these up with tweakable parameters up top at some future point.

Script for creating students

Create Users

This script creates student user accounts based on a CSV file with the following structure:

username, first, last, group, password

' Script to create student accounts
' Created by Tom Hinkle
' (or, if he's moved on,
' Requires file named students.csv in same directory with requisite information.
' File format is plain csv (no escaping) as follows:
' username, first, last, year-of-grad, password
' Note that year-of-grad is used for group names. We expect there to be an OU
' with the name of e.g. YOG2012 for each year-of-grad. Also, student folders
' are named by YOG, so we expect the students folder to contain a folder titled
' e.g. YOG2012

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
upnSuffix = ""
Set objRootDSE = GetObject("LDAP://rootDSE")

dim fs,objTextFile
set fs=CreateObject("Scripting.FileSystemObject")
dim arrStr
set objTextFile = fs.OpenTextFile("students.csv")

Do while NOT objTextFile.AtEndOfStream
arrStr = split(objTextFile.ReadLine,",")
givenName = arrStr(1)
lastName = arrStr(2)
sn = lastName
cn = givenName & " " & lastName
OU = "YOG" & arrStr(3)
samAccountName = arrStr(0)
' Specify the NetBIOS name of the domain.
strNetBIOSDomain = "cpcs"
userPrincipalName = samAccountName & "@" & upnSuffix
homedir = "\\\students\" & OU & "\" & samAccountName
groupname = "LDAP://ou=" & OU & ",ou=Student,DC=CPCS,DC=com"

Set objContainer = GetObject(groupname)
Set objUser = objContainer.Create("User", "cn=" & cn)
objUser.Put "sAMAccountName", samAccountName
objUser.Put "userPrincipalName", userPrincipalName
objUser.Put "sn", sn
objUser.Put "givenName", givenName
objUser.Put "displayName", givenName & " " & sn
objUser.Put "userAccountControl", 512
objUser.Put "homeDirectory", homedir
objUser.Put "homeDrive", "H"
objUser.Put "scriptPath", "SLogon.bat"

On Error Resume Next
If (Err.Number <> 0) Then
Wscript.Echo "Unable to create " & samAccountName
End If
'On Error GoTo 0

objUser.SetPassword arrStr(4)

' Create folder, based on:

If (objFSO.FolderExists(homedir) = False) Then
' Create folder.
On Error Resume Next
objFSO.CreateFolder homedir
If (Err.Number <> 0) Then
Wscript.Echo "Unable to create home directory for " & strSAM
End If
On Error GoTo 0
End If
If (objFSO.FolderExists(homedir) = True) Then
' Assign permissions to home directory.
intRunError = objShell.Run("%COMSPEC% /c echo Y| cacls " _
& homedir & " /T /E /C /G " & strNetBIOSDomain _
& "\" & samAccountName& ":F", 2, True)
If (intRunError <> 0) Then
Wscript.Echo "Unable to assign permissions for " & samAccountName
End If
End If
set objTextFile = Nothing
set fs = Nothing
wscript.Echo("When you are done, you will want to go into active directory, highlight the new users manually, and add them to the group Students. You'll also need to disallow changing the password. Sorry I didn't get this done programmatically, but it's relatively simple to do manually")