26 May 2010

Packing files together, then splitting them: tar

The tar program is so useful for packing files together for transport.  With all the talk of cloud storage and all, especially now with Ubuntu One, there's still sometimes a place for good ol' email it to yourself storage.  Except that email servers typically won't let you upload files larger than 10 or 20 MB.

The solution is to archive the files into one, then split it into say 10 MB segments.

Say all the files are in a directory src-code.  Then do tar -czf src-code.tgz src-code.  That'll pack the whole directory into one zipped and archive file.

Then to split it into approximately 10 MB segments, do tar -ML 10240 -cf src-code.part1.tgz src-code.tgz. This will return an interactive session, where it'll ask you for the name of the next segment to save as, at which point you'll want to do n src-code.part2.tgz for the second segment, and so on (do ? and return-key for help).

To reverse the process, do tar -Mxf src-code.part1.tgz and then n src-code.part2.tgz and so on at the interactive prompt.  Then tar -xzf src-code.tgz to get back the src-code directory.

25 May 2010

Ubuntu Lucid: Restarting X Server

Strangely, on my desktop computer, sometimes the Nvidia driver doesn't get used properly on startup or restart, resulting in an ultra low display resolution.  This sometimes occur, and sometimes doesn't.  Very frustrating.

Fortunately, a one-shot solution is just to restart the X Server.  Go to a terminal, eg, by keying Ctrl-Alt-F7 to go to a tty after reaching the log-in screen at startup.  Then do sudo restart gdm.

This requires that you can use sudo of course.  At least with Ubuntu, that's the same as doing sudo /etc/init.d/gdm restart.

On startup, Ubuntu does detect the problem and offers a choice to restart the X server, but that somehow doesn't work.  Doing this manually at a terminal does though.  Weird.

18 May 2010

Raising children without discomfort

Take a look at the article, Weaponizing Mozart. It's incredible the ingenuity put into thinking up devices like the Mosquito, techniques like shining bright halogen lights from helicopters, or forcing children in detention to listening to classical music, in order to influence or modify the children's behaviour.

Essentially it's putting all this time and effort into modifying children's behaviour without subjecting adults to the discomfort experienced in confronting and personally working with the children to change.

It's as if for some parents, teachers, and adults, they don't mind at all spending more money, time, and resources on the problem. Whatever it takes, so long as they don't have to actually face a child, build a relationship with the child, and work with the child constantly over time to internalize better and more effective behaviours.

16 May 2010

Dear Grade 9s: What algebraic equations are for

A friend of mine was making an algebra test for his junior high math class recently and asked me what I thought equations are for.  What he meant is that the students are required to write out an equation for a given word problem before solving the equation, but students are bound to ask what the point of writing an equation is if they can solve it without it.

For assessment purposes, of course teachers need to see students write out an equation to know that they can.  But for students, the problems are probably easy enough that they don't really need to write out an equation to solve the problem, and so they see no point in doing the extra algebraic work!  Of course, they have also been trained over the years to recognize nice, round numbers as "The Answer" to all types of questions, so it's hard for them to understand how an equation can be part of "The Answer."

So here's a simple reason that I might give to a hypothetical grade 9 class: the point of writing an equation is to communicate an argument, and to tell the reader what the writer thinks is in fact true reality.

15 May 2010

Few reminders to the very 1st steps to application development in Clojure

Just a few reminders for myself for now...

Get lein.
Get emacs with elpa; use it to get swank-clojure into emacs.

Do lein new project_name
Modify project.clj to use Incanter and Swank, so it should include something like this:

:dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"]
              [org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]
              [incanter "1.2.3-SNAPSHOT"]]
:dev-dependencies [[swank-clojure "1.2.1"]
                   [jline "0.9.94"]]

(edit: turns out incanter will use/import the right clojure libraries for you, but you still should specify which version of clojure and contrib you want to use.  Also note leiningen/lein-swank "1.1.0" is being replaced by swank-clojure)

Do lein deps
Do lein swank
From emacs, do M-x slime-connect

Write your code in files in src/project_name
From the repl in emacs, do (load-file "path/to/code_file.clj") to load the code so you can run it manually to inspect it.  Do (remove-ns 'main-ns-in-code-file) to start over and re-load the file for further inspection (say after you'd done some edits).

(edit: unfortunately, it looks like Java doesn't allow dynamically changing the classpath, so if you write a new file new_file.clj then you'll have to restart the repl or the swank server)

Oh, make sure file names do not include the "-" character even if the namespace you use has a "-" character in it; replace it with a "_" instead in the file name (the namespace can continue to use the "-" though).

You'll need a -main function and an addition to the project.clj file, but that's all I want to note down for now.

(edit: also check out this intro for more readable info from the Incanter web site. My stuff above was more like a brain-dump of mental notes.)

Namespaces in Clojure

The only succinct documentation of namespaces I found on Clojure is here.  To quote Brian there:
:refer shouldn't be used by you at all.

:import brings in java classes

:use brings in the names from another clojure namespace without requiring namespace qualifications

:require brings in the names from another clojure namespace requiring namespace qualifications.

So if ns foo has a var bar, if you do (use 'foo), you can just refer to bar, but if you do (require 'foo), you have to say foo/bar, not just bar.
I should add: make sure file names do not include the "-" character even if the namespace you define with (ns ...) has a "-" character in it; replace it with a "_" instead in the file name (the namespace can continue to use the "-" though).

(edit: I will write more about namespaces, especially the syntax of the (ns ...) later.)

08 May 2010

Is my hard disk failing?

On my Dell Mini, Ubuntu 10.04 Lucid Lynx has this Disk Utility program (palimpset) that keeps saying I have 200+ bad blocks on the disk, but also that the hard disk is "healthy".  Apparently this is a problem with that program.  Instead, install gsmartcontrol from Synaptic and use that to check out the SMART status of your hard disk.  That shows my disk actually has had no bad blocks, which agrees with what the disk utility from Windows 7 says (the name of this utility escapes me at this time).

07 May 2010

User Home encryption on Ubuntu 10.04 Lucid Lynx

As I mentioned earlier, encrypting a home user's folder is ultra easy now in Ubuntu, at least for creating a new user (switching an existing user over to using an encrypted home is still pretty complicated).  Just go to Users and Groups to add a new user, making sure to click the check-box option to enable encryption.

But that's not good enough. You need to encrypt your swap partition as well, since anything in RAM could be swapped out onto the swap partition on disk and be read back at a later time.  Turns out this is easy to do in Ubuntu as well.

You'll need to install cryptsetup from the Synaptic Package Manager and of course ecryptfs must also have been installed previously as well (you'd need to have had that installed to enable encrypted user folders in the first place, but I just can't recall if that was installed as part of the standard Lucid Lynx distribution or if I had installed it myself afterwards...).

Once cryptsetup is installed, just do sudo ecryptfs-setup-swap.  Read the warning that's thrown up, it explains to you that at this time, hibernation is incompatible with encrypted swap (although suspend works fine), and indicate your agreement (or not to cancel the procedure).

You don't need to have logged out or anything.  This command will work on its own, or at least it did for me without any special prior setting up.  Once that's done, you can verify it by checking less /etc/fstab to see if the original swap disk setup had been commented out and a new encrypted disk is set up for swap in its place.

Once that's done, you should look into securely erasing the free space on the swap and the root volumes to ensure anything sensitive that's been "spilled" out of encryption containment in the past gets cleaned up now.  You'll need the secure-delete package of tools, specifically sfill and sswap.  See this answer for details.

[Edit: Actually, I recommend looking into securely erasing the free space on swap before encrypting it.  Would've made the process just a tad bit more convenient.]

Re: High Academic Results Make Better Programmers

Alan Skorkin argues that "High Academic Results Make Better Programmers", or approximately that with certain caveats.  He's writing to try to balance out the view that often denigrates high marks and high academic achievements as he notes.

I generally agree with what he says there, and I think some more details can be given to support why good academic performance is important to programmers. So here goes.

Education is expensive, so a university graduate with low marks raises a question about his or her priorities.  Of course, if the marks are low and many impressive personal programming projects were also completed, projects that are relevant to the job being applied to or whatever, then the low marks might be looked at differently.

But then again, between two candidates, both having completed a wealth of relevant personal programming projects, but one has higher GPA than the other, it's obvious to me who would get hired.

Or look at it another way.  Hiring a university graduate with a high GPA could mean hiring someone who is simply exceptional, or someone who is a grade chasing conformist who'll adapt and do whatever it takes to get a high GPA (or a high pay) — some people apparently believe that's what a high GPA indicates.