Shallow Thoughts : : Feb
Akkana's Musings on Open Source Computing and Technology, Science, and Nature.
Fri, 24 Feb 2017
We have a terrific new program going on at
Los Alamos Makers:
a weekly Coder Dojo for kids, 6-7 on Tuesday nights.
Coder Dojo is a worldwide movement,
and our local dojo is based on their ideas.
Kids work on programming projects to earn colored USB wristbelts,
with the requirements for belts getting progressively harder.
Volunteer mentors are on hand to help, but we're not lecturing or
teaching, just coaching.
Despite not much advertising, word has gotten around and we typically
have 5-7 kids on Dojo nights, enough that all the makerspace's
Raspberry Pi workstations are filled and we sometimes have to scrounge
for more machines for the kids who don't bring their own laptops.
A fun moment early on came when we had a mentor meeting, and Neil,
our head organizer (who deserves most of the credit for making this
program work so well), looked around and said "One thing that might
be good at some point is to get more men involved." Sure enough --
he was the only man in the room! For whatever reason, most of the
programmers who have gotten involved have been women. A refreshing
change from the usual programming group.
(Come to think of it, the PEEC web development team is three women.
A girl could get a skewed idea of gender demographics, living here.)
The kids who come to program are about 40% girls.
I wondered at the beginning how it would work, with no lectures or
formal programs. Would the kids just sit passively, waiting to be
spoon fed? How would they get concepts like loops and conditionals
and functions without someone actively teaching them?
It wasn't a problem. A few kids have some prior programming practice,
and they help the others. Kids as young as 9 with no previous
programming experience walk it, sit down at a Raspberry Pi station,
and after five minutes of being shown how to bring up a Python console
and use Python's turtle graphics module to draw a line and turn a corner,
they're happily typing away, experimenting and making Python draw
great colorful shapes.
Python-turtle turns out to be a wonderful way for beginners to learn.
It's easy to get started, it makes pretty pictures, and yet, since
it's Python, it's not just training wheels: kids are using a real
programming language from the start, and they can search the web and
find lots of helpful examples when they're trying to figure out how to
do something new (just like professional programmers do. :-)
Initially we set easy requirements for the first (white) belt: attend
for three weeks, learn the names of other Dojo members. We didn't
require any actual programming until the second (yellow) belt, which
required writing a program with two of three elements: a conditional,
a loop, a function.
That plan went out the window at the end of the first evening, when
two kids had already fulfilled the yellow belt requirements ... even
though they were still two weeks away from the attendance requirement
for the white belt. One of them had never programmed before. We've
since scrapped the attendance belt, and now the white belt has the
conditional/loop/function requirement that used to be the yellow belt.
The program has been going for a bit over three months now. We've
awarded lots of white belts and a handful of yellows (three new ones
just this week). Although most of the kids are working in Python,
there are also several playing music or running LED strips using
Arduino/C++, writing games and web pages in Javascript, writing
adventure games Scratch, or just working through Khan Academy lectures.
When someone is ready for a belt, they present their program to
everyone in the room and people ask questions about it: what does that
line do? Which part of the program does that? How did you figure out
that part? Then the mentors review the code over the next week, and
they get the belt the following week.
For all but the first belt, helping newer members is a requirement,
though I suspect even without that they'd be helping each other. Sit a
first-timer next to someone who's typing away at a Python program and
watch the magic happen. Sometimes it feels almost superfluous being a
mentor. We chat with the kids and each other, work on our own projects,
shoulder-surf, and wait for someone to ask for help with harder problems.
Overall, a terrific program, and our only problems now are getting
funding for more belts and more workstations as the word spreads and
our Dojo nights get more crowded. I've had several adults ask me if
there was a comparable program for adults. Maybe some day (I hope).
Tags: programming, education
[
13:46 Feb 24, 2017
More programming |
permalink to this entry |
]
Sat, 18 Feb 2017
I recently got annoyed with all the trailing whitespace I saw in files
edited by Windows and Mac users, and in code snippets pasted from
sites like StackOverflow. I already had my emacs set up
to indent with only spaces:
(setq-default indent-tabs-mode nil)
(setq tabify nil)
and I knew about
M-x delete-trailing-whitespace
... but after seeing someone else who had an editor set up to show
trailing spaces, and tabs that ought to be spaces, I wanted that too.
To show trailing spaces is easy, but it took me some digging to
find a way to control the color emacs used:
;; Highlight trailing whitespace.
(setq-default show-trailing-whitespace t)
(set-face-background 'trailing-whitespace "yellow")
I also wanted to show tabs, since code indented with a mixture of tabs
and spaces, especially if it's Python, can cause problems.
That was a little harder, but I eventually found it on the
EmacsWiki:
Show whitespace:
;; Also show tabs.
(defface extra-whitespace-face
'((t (:background "pale green")))
"Color for tabs and such.")
(defvar bad-whitespace
'(("\t" . 'extra-whitespace-face)))
While I was figuring this out, I got some useful advice related to emacs
faces on the #emacs IRC channel: if you want to know why something is
displayed in a particular color, put the cursor on it and type
C-u C-x = (the command what-cursor-position with
a prefix argument), which displays lots of information about
whatever's under the cursor, including its current face.
Once I had my colors set up,
I found that a surprising number of files I'd edited with vim had
trailing whitespace. I would have expected vim to be better behaved
than that! But it turns out that to eliminate trailing whitespace,
you have to program it yourself. For instance, here are some recipes to
Remove
unwanted spaces automatically with vim.
Tags: editors, emacs
[
16:41 Feb 18, 2017
More linux/editors |
permalink to this entry |
]
Mon, 13 Feb 2017
Part of being a programmer is having an urge to automate repetitive tasks.
Every new HTML file I create should include some boilerplate HTML, like
<html><head></head></body></body></html>
.
Every new Python file I create should start with
#!/usr/bin/env python
, and most of them should end
with an if __name__ == "__main__":
clause.
I get tired of typing all that, especially the dunderscores and
slash-greater-thans.
Long ago, I wrote an emacs function called newhtml
to insert the boilerplate code:
(defun newhtml ()
"Insert a template for an empty HTML page"
(interactive)
(insert "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
"<html>\n"
"<head>\n"
"<title></title>\n"
"</head>\n\n"
"<body>\n\n"
"<h1></h1>\n\n"
"<p>\n\n"
"</body>\n"
"</html>\n")
(forward-line -11)
(forward-char 7)
)
The motion commands at the end move the cursor back to point in
between the <title> and </title>, so I'm ready to type
the page title. (I should probably have it prompt me, so it can insert
the same string in title
and h1
, which
is almost always what I want.)
That has worked for quite a while. But when I decided it was time to
write the same function for python:
(defun newpython ()
"Insert a template for an empty Python script"
(interactive)
(insert "#!/usr/bin/env python\n"
"\n"
"\n"
"\n"
"if __name__ == '__main__':\n"
"\n"
)
(forward-line -4)
)
... I realized that I wanted to be even more lazy than that.
Emacs knows what sort of file it's editing -- it switches to html-mode
or python-mode as appropriate. Why not have it insert the template
automatically?
My first thought was to have emacs run the function upon loading a
file. There's a function with-eval-after-load
which
supposedly can act based on file suffix, so something like
(with-eval-after-load ".py" (newpython))
is documented to work. But I found that it was never called, and
couldn't find an example that actually worked.
But then I realized that I have mode hooks for all the programming
modes anyway, to set up things like indentation preferences. Inserting
some text at the end of the mode hook seems perfectly simple:
(add-hook 'python-mode-hook
(lambda ()
(electric-indent-local-mode -1)
(font-lock-add-keywords nil bad-whitespace)
(if (= (buffer-size) 0)
(newpython))
(message "python hook")
))
The (= (buffer-size) 0)
test ensures this only happens
if I open a new file. Obviously I don't want to be auto-inserting code
inside existing programs!
HTML mode was a little more complicated. I edit some files, like
blog posts, that use HTML formatting, and hence need html-mode,
but they aren't standalone HTML files that need the usual HTML
template inserted. For blog posts, I use a different file extension,
so I can use the elisp string-suffix-p
to test for that:
;; s-suffix? is like Python endswith
(if (and (= (buffer-size) 0)
(string-suffix-p ".html" (buffer-file-name)))
(newhtml) )
I may eventually find other files that don't need the template;
if I need to, it's easy to add other tests, like the directory where
the new file will live.
A nice timesaver: open a new file and have a template automatically
inserted.
Tags: emacs, editors, programming
[
09:52 Feb 13, 2017
More linux/editors |
permalink to this entry |
]
Sun, 05 Feb 2017
Los Alamos is having an influx of rare rosy-finches (which apparently
are supposed to be hyphenated:
they're rosy-finches, not finches that are rosy).
They're normally birds of the snowy high altitudes, like the top of
Sandia Crest, and quite unusual in Los Alamos. They're even rarer in
White Rock, and although I've been keeping my eyes open I haven't seen
any here at home; but a few days ago I was lucky enough to be invited
to the home of a birder in town who's been seeing great flocks of
rosy-finches at his feeders.
There are four types, of which three have ever been seen locally,
and we saw all three. Most of the flock was brown-capped rosy-finches,
with two each black rosy-finches and gray-capped rosy-finches.
The upper bird at right, I believe, is one of the blacks, but it
might be a grey-capped. They're a bit hard to tell apart.
In any case, pretty birds, sparrow sized with nice head markings and
a hint of pink under the wing, and it was fun to get to see them.
The local roadrunner also made a brief appearance, and we marveled at
the combination of high-altitude snowbirds and a desert bird here at
the same place and time. White Rock seems like much better roadrunner
territory, and indeed they're sometimes seen here (though not, so far,
at my house), but they're just as common up in the forests of Los Alamos.
Our host said he only sees them in winter; in spring, just as they
start singing, they leave and go somewhere else. How odd!
Speaking of birds and spring, we have a juniper titmouse determinedly
singing his ray-gun song, a few house sparrows are singing
sporadically, and we're starting to see cranes flying north. They
started a few days ago, and I counted several hundred of them today,
enjoying the sunny and relatively warm weather as they made their way
north. Ironically, just two weeks ago I saw a group of about sixty
cranes flying south -- very late migrants, who must have
arrived at the Bosque del Apache just in time to see the first
northbound migrants leave. "Hey, what's up, we just got here, where ya
all going?"
A few more photos:
Rosy-finches
(and a few other nice birds).
We also have a mule deer buck frequenting our yard, sometimes hanging
out in the garden just outside the house to drink from the heated
birdbath while everything else is frozen. (We haven't seen him in a
few days, with the warmer weather and most of the ice melted.) We know
it's the same buck coming back: he's easy to recognize because he's
missing a couple of tines on one antler.
The buck is a welcome guest now, but in a month or so when the trees
start leafing out I may regret that as I try to find ways of keeping
him from stripping all the foliage off my baby apple tree, like some
deer did last spring. I'm told it helps to put smelly soap shavings,
like Irish Spring, in a bag and hang it from the branches, and deer
will avoid the smell. I will try the soap trick but will probably
combine it with other measures, like a temporary fence.
Tags: nature, birds
[
19:39 Feb 05, 2017
More nature/birds |
permalink to this entry |
]