Category Archives: geek

Thinking about problem-solving and sequencing

We’ve been helping J- with her culminating project in Grade 11 programming class, a text-based blackjack game. She was getting stuck because she wasn’t comfortable enough with Java or programming. She didn’t know where to start or what to do. I didn’t write the program for her (and that was never on the table, anyway), but I offered to guide her through the process. More experienced learners can do that kind of planning on their own, but when you’re new to a subject (and especially if you’re under time pressure), it helps to have that kind of scaffolding.

The first thing I did was to properly set up Eclipse on her computer. She had already tried setting it up, but it kept quitting with a cryptic error message. I realized that she didn’t have the Java software development kit installed. Once we added that, Eclipse started working.

Then I set up a sequence of tiny, tiny steps that she could implement with a little guidance. This was not the same sequence of events that would be in the final game: betting, shuffling, dealing, scoring, and so on. Instead, I focused on the steps she could build on bit by bit. It went something like this:

  1. Display a random number.
  2. Initialize the deck array based on the face array and suit array J- had already set up. This would contain strings like “ace of hearts”.
  3. Print the deck array.
  4. Set up a parallel array of card values, and print that as well. This would contain integers such as 1 for ace.
  5. Shuffle the deck by swapping each card with a random card, swapping the same card’s value as well.
  6. Write a function that takes an array of card values and returns the value of the hand.
  7. Modify the function to take aces into account, since aces could be either 1 or 11.
  8. Handle the initial dealing of two cards each by keeping track of the top card and updating a status array.
  9. Display the cards for a specified hand based on the status array.
  10. Update the hand value function to take the status array into account.
  11. Deal cards to the player as requested.
  12. Check if the player has lost.
  13. Follow the rules for dealing additional cards to the dealer.
  14. Check if the dealer has lost.
  15. Figure out who won that round.
  16. Read the bet.
  17. Update the bet after the player has won or lost the round.
  18. Check if the player has doubled their money or lost all their money.
  19. Add more error-checking.
  20. Add more flexibility.

2015-06-11a Blackjack implementation sequence -- index card #sequencing #problem-solving

2015-06-11a Blackjack implementation sequence – index card #sequencing #problem-solving

This sequence meant that she could write and test the less-interactive parts first (preparing the deck, shuffling the cards, calculating the score) before slowing down her compile-run-test cycle with input. It also let her work on the simplest parts first without writing a lot of redundant code and with just a little prompting from me.

Instead of this zigzag path, we could have followed the chronological flow of the program, especially if I introduced her to the practice of stubbing functions until you’re ready to work on them. This shuffled order felt a bit better in terms of demonstrable progress, and she seems to have been able to follow along with the construction process. In retrospect, the chronological flow might have been easier for her to learn and apply to other projects, though, since breaking down and shuffling the order of tasks is a skill that programming newbies probably need a while to develop.

Anyway, helping J- with her project got me thinking about how I work my way through programming challenges on my personal projects and in my consulting. I tend to try to figure things out by myself instead of asking mentors or the Internet. I also tend to write things in a bottom-up instead of top-down order: starting with small things I can write and test quickly, and then gradually building more elaborate processes around them.

2015-06-09e What do I mean by sequencing -- index card #learning #problem-solving #sequencing

2015-06-09e What do I mean by sequencing – index card #learning #problem-solving #sequencing

I think of the process of breaking down tasks and organizing them into a useful order as “sequencing”, which is part of the general domain of problem-solving. There’s probably an official term for it, but until I find it, that’s the term makes sense to me. When I was teaching undergraduate computer science, I noticed that students often struggled with the following aspects:

  • Imagining a good goal, if they were doing a self-directed project (not too big, not too small, etc.)
  • Fleshing out their goal into specifications
  • Identifying possible chunks along the path
  • Breaking those chunks down into smaller chunks as needed
  • Figuring out how to bridge those chunks together
  • Prioritizing chunks
  • Re-evaluating paths, progress, and goals as they learned more
  • Managing motivation
  • Finding resources
  • Translating or adapting those resources to what they needed to do
  • Figuring out what they could start with (what they already knew, or that first hand-hold on a chunk)

2015-06-09h Sequencing challenges -- index card #learning #problem-solving #sequencing #challenges

2015-06-09h Sequencing challenges – index card #learning #problem-solving #sequencing #challenges

I sometimes have a hard time with these aspects too, especially when I’m learning a new toolkit or language. I think I’m getting better at picking ridiculously tiny steps and celebrating that progress instead of getting frustrated by blocks. When I can’t figure tiny steps out, I know that going through tutorials and reading other people’s code will help me build my vocabulary. That way, I can get better at finding resources and planning chunks. I have a better idea of what’s out there, what things are called, and maybe even what’s probably harder and what’s probably easier.

2015-06-09f How do I develop my own sequencing skills -- index card #learning #problem-solving #sequencing

2015-06-09f How do I develop my own sequencing skills – index card #learning #problem-solving #sequencing

Programming gives me plenty of opportunities to develop my sequencing skills. By writing notes with embedded code snippets and TODOs, I can break large chunks down into smaller chunks that fit in my working memory. Sometimes I read programming documentation or source code without any particular project in mind, just collecting ideas and expanding my imagination. If I focus on writing tiny chunks that start off as “just good enough” rather than making them as elaborate as I can, that lets me move on to the rest of the program and get feedback faster. Saving snippets of unused or evolving code (either manually in my notes or automatically via a version contro system) lets me reuse them elsewhere.

I imagine that getting even better at sequencing might involve:

  • Sharing intermediate or neighbouring products to get feedback faster and create more value
  • Figuring out (and remembering!) sequences for getting into various areas such as Angular or D3
  • Becoming fluent with many styles of sequencing, like working top-down instead of just bottom-up
  • Building reliable automated tests along the way, even as my understanding of the project evolves

What about helping other people get better at sequencing?

2015-06-09g How can I help other people develop sequencing skills -- index card #learning #problem-solving #sequencing

2015-06-09g How can I help other people develop sequencing skills – index card #learning #problem-solving #sequencing

  1. If I share a pre-defined sequence, that helps people with less experience follow a possibly more efficient path.
  2. If I customize the sequence for someone I’m helping, that’s even more useful.
  3. Talking about how we’re customizing the sequence exposes sequencing as a skill.
  4. Guiding someone through the breakdown of a small chunk (from a task to pseudocode, for example) can help them get the hang of turning things into specifics.
  5. Guiding someone through the breakdown of a larger chunk into smaller chunks helps them think of larger chunks as doable.
  6. Once someone has identified a few chunks, I can help with prioritizing them based on effort, relationship between chunks, etc.
  7. In preparation for independent learning, it’s good to practice the skill of figuring out those prioritization factors: small experiments, research, and so on.
  8. And at some point (woohoo!), I can help someone reflect on and tweak a plan they developed.

I’m not yet at the point of being able to do even step 1 well, but maybe someday (with lots of practice)!

Since this is a super-useful skill and not everyone’s into programming, it might be interesting to look around for non-programming situations that can help develop sequencing skills.

2015-06-09i Non-programming examples of sequencing -- index card #learning #problem-solving #sequencing

2015-06-09i Non-programming examples of sequencing – index card #learning #problem-solving #sequencing

On the passive side, it’s interesting to learn about how things work or how they’re made. Better yet, you can actively practise sequencing with math problems, video games with quests… Writing is like this too, if you think of key points and use tools such as outlines or index cards. Making things involves imagining what you want and figuring out lots of small steps along the way. Life is filled with little opportunities for everyday problem-solving.

I’d love to learn more about this. Chunk decomposition? Problem-solving order? Problem decomposition? Step-wise refinement? I’m more comfortable with bottom-up problem-solving, but top-down solving has its merits (focus, for one), so maybe I can practice that too. Using both approaches can be helpful. (Ooh, there’s a Wikipedia article on top-down and bottom-up design…) Time to check out research into the psychology of problem-solving!

Using Emacs Org Mode tables to calculate doses to buy

I got tired of manually calculating how many I needed to buy based on a daily protocol and how many I had in stock, so I wrote a little bit of Emacs Lisp to figure it out. You can specify the type, daily dose, start and end dates (inclusive; defaults to the last specified date if blank), and how many you have in stock.

First, define a table of this form, and give it a name.

#+NAME: input
| Type         | Per day |      Start |        End | Stock |
| Medication A |       2 | 2015-06-09 | 2015-06-16 |     5 |
| Medication B |       1 |            |            |     0 |
| Medication C |     0.1 | 2015-06-12 | 2015-06-16 |   0.2 |
Type Per day Start End Stock
Medication A 2 2015-06-09 2015-06-16 5
Medication B 1 0
Medication C 0.1 2015-06-12 2015-06-16 0.2

To call the code from the bottom of this post, use something like:

#+CALL: calculate-meds-needed(meds=input) :hlines yes :colnames yes
Type Total In stock Needed
Medication A 16 5 11
Medication B 8 0 8
Medication C 0.5 0.2 1

Here’s the code that processes it:

#+name: calculate-meds-needed :var meds=meds :colnames yes :hlines yes
#+begin_src emacs-lisp
(let (start end)
   (list (list "Type" "Total" "In stock" "Needed"))
   (list 'hline)
   (sort (delq nil (mapcar
                    (lambda (row)
                      (unless (or (eq row 'hline) (string= (elt row 0) "Type"))
                        (let (total)
                          (setq start (if (string< "" (elt row 3)) (elt row 3) start)
                                end (if (string< "" (elt row 2)) (elt row 2) end)
                                total (* (elt row 1)
                                         (- (calendar-absolute-from-gregorian (org-date-to-gregorian start))
                                            (calendar-absolute-from-gregorian (org-date-to-gregorian end))
                           (elt row 0)
                           (elt row 4)
                           (max 0 (ceiling (- total (elt row 4))))))))
                    meds)) (lambda (a b) (string< (car a) (car b))))))

Adding calculations based on time to the Org Agenda clock report

Duplicating this answer on my blog in case StackOverflow goes away. =)

Leo asked:

I’m trying to make the Agenda Clockreport show how many pomodoros I’ve invested in a task. A Pomodoro is 25 minutes. For example, 1:15 hours of work is 3 pomodoros.

I’m trying to customize org-agenda-clockreport-paramater-plist, and I would like to extract “Time” and convert it to a pomodoro. I.e., (time in minutes / 25) = pomodoro.

I wrote:

This will create a column in your clocktable report that sums the hours from columns 3 and 4, and then another column that shows you the round number of pomodoros that took up.

(setq org-agenda-clockreport-parameter-plist
      '(:link t :maxlevel 2 :formula "$5=$3+$4;t::$6=ceil($5*60/25);N"))

If you don’t want in-between columns, here’s a totally hackish approach:

(defun my/org-minutes-to-clocksum-string (m)
  "Format number of minutes as a clocksum string.
Shows the number of 25-minute pomodoros."
  (format "%dp" (ceiling (/ m 25))))
(fset 'org-minutes-to-clocksum-string 'my/org-minutes-to-clocksum-string)

Alternatively, you can use :formatter, but the formatting function looks very long and annoying to change.

Leo eventually configured it with:

(setq org-agenda-clockreport-parameter-plist
 '(:fileskip0 t :link t :maxlevel 2 :formula "$5=($3+$4)*(60/25);t"))

(He didn’t mind the decimals, I guess! =) )

Recreating and enhancing my tracking interface by using Tasker and Javascript

I got tired of setting up Tasker scripts by tapping them into my phone, so I looked into how to create Tasker interfaces using Javascript. First, I created a folder in Dropbox, and I used Dropsync to synchronize it with my phone. Then I created a simple test.html in that folder. I created a Tasker scene with a WebView that loaded the file. Then I started digging into how I can perform tasks, load applications, and send intents to Evernote so that I can create notes with pre-filled text. I really liked being able to reorder items and create additional screens using Emacs instead of Tasker’s interface.

Here’s my code at the moment. It relies on other Tasker tasks I’ve already created, so it’s not a standalone example you can use right off the bat. Still, it might be useful for ideas.


        <title>Sacha's personal tracking interface</title>
        <style type="text/css">
         button { padding: 20px; font-size: large; width: 45%; display: inline-block  }
        <script type="text/javascript" src=""></script>
        <div id="feedback"></div>
        <!-- For making it easy to track things -->
        <div class="screen" id="main-screen">
        <button class="note">Do</button>
        <button class="note">Think</button>
        <button class="note">Note</button>
        <button class="note">Journal</button>
        <button class="switch-screen" data-screen="track-screen">Track</button>
        <button class="switch-screen" data-screen="play-screen">Play</button>
        <button class="switch-screen" data-screen="eat-screen">Eat</button>
        <button class="switch-screen" data-screen="energy-screen">Energy</button>
        <button id="reload">Reload</button>
        <div class="screen" id="play-screen">
            <button class="play">Persona 3</button>
            <button class="play">Ni No Kuni</button>
            <button class="play">Hobbit</button>
            <button class="switch-screen"
        <div class="screen" id="energy-screen">
            <button class="energy">5</button><br />
            <button class="energy">4</button><br />
            <button class="energy">3</button><br />
            <button class="energy">2</button><br />
            <button class="energy">1</button><br />
            <button class="switch-screen"
        <div class="screen" id="eat-screen">
            <button class="eat">Breakfast</button>
            <button class="eat">Lunch</button>
            <button class="eat">Dinner</button>
            <button class="switch-screen"
        <div class="screen" id="track-screen">
            <button class="update-qa">Routines</button>
            <button class="update-qa">Subway</button>
            <button class="update-qa">Coding</button>
            <button class="update-qa">E1 Gen</button>
            <button class="update-qa">Drawing</button>
            <button class="update-qa">Cook</button>
            <button class="update-qa">Kitchen</button>
            <button class="update-qa">Tidy</button>
            <button class="update-qa">Relax</button>
            <button class="update-qa">Family</button>
            <button class="update-qa">Walk Other</button>
            <button class="update-qa">Nonfiction</button>
            <button class="update-qa">Laundry</button>
            <button class="update-qa">Sleep</button>
            <button id="goToWeb">Web</button>
            <button class="switch-screen" data-screen="main-screen">Back</button>
         function updateQuantifiedAwesome(category) {
             performTask('Update QA', null, category);

         function showFeedback(s) {
         function switchScreen(s) {
             $('#' + s).show();

         $('.switch-screen').click(function() {
         function createEvernote(title, body) {
             sendIntent('com.evernote.action.CREATE_NEW_NOTE', 'activity',
                        '', '', 'none', '', '',
                        ['android.intent.extra.TITLE:' + (title || ''),
                         'android.intent.extra.TEXT:' + (body || '')]);
         $('.note').click(function() {
         $('.energy').click(function() {
             createEvernote('Energy', 'Energy ' + $(this).text() + ' ');
         $('#reload').click(function() {
             performTask('Reload Test');
         $('.update-qa').click(function() {
             updateQuantifiedAwesome($(this).attr('data-cat') || $(this).text());
             hideScene('Test View');
         $('#goToWeb').click(function() {
         $('.eat').click(function() {
         $('.play').click(function() {
             performTask('Play', null, $(this).text());



You can find the latest version at

Thinking about simplifying capture on my phone

I’ve been thinking about temporary information: things like where I put down something I was holding, the task I’m working on just in case I get interrupted, thoughts that I want to explore later on.

The seeds of a good system are there, if I learn how to use them more effectively. I usually have my phone handy. Evernote can record audio, pictures, or text, and the creation date is an automatic timestamp. I can export the notes and process them using Emacs. Google Now’s “Note to self” command can create a note in Evernote, or I can tap the Create Note icon.

How can I improve how I use these tools?

If I get used to starting my note lines with a special keyword, then it’ll be easier for me to extract those lines and process them. For example:

DO Actions to add to my to-do list
THINK Thoughts to explore
PLACE Putting things down

If I add custom commands to Google Now, or make Google Now the fallback for another command line, then I can use that for my tracking system as well. AutoShare and AutoVoice might be handy. I should probably learn how to get Tasker working with Javascript, too. Alternatively, I can use Evernote’s e-mail interface, although there might be a slight delay if I’m offline.

If I create a custom single-click interface that can start the note with a specified keyword, that would be even better.

I could also use a more systematic review process. For example:

  • All THINK items can be automatically added to the end of my as their own headings.

  • All DO items can be added to my uncategorized tasks.

Okay, let’s start by figuring out Javascript and Tasker, since that will make it easier for me to write actions that take advantage of intents.

First step is to save the JS library template from Tasker. The file is stored in /storage/emulated/0/Tasker/meta/tasker.js. Okay, I’ve created a Tasker scene that has a WebView component that loads the file that I synchronized with Dropsync.

The next step is to simplify development so that I can try things quickly. I want to be able to sync and reload my WebView scene by tapping a button. The Dropsync Tasker action returns immediately, so maybe I’ll just add a wait to it.

Hmm, maybe a good path might be:

  1. Set up easy sync/reload, so I can try things out quickly.
  2. Include JQuery.
  3. Run tasks.
  4. Launch apps.
  5. Send intents.
  6. Convert my current tracking menu to this format.
  7. Add buttons for creating notes (either e-mail-based or intent-based):
    • Do
    • Think
    • Place
  8. Add a command-line. Compare using it vs. using buttons.

On a related note, what kinds of things would I like my phone to be smart enough to do?

  • If I’m at home and I’m calling my cellphone from our home phone, set the ring volume to maximum, since that means I’m trying to find it.
  • If I say that I’m at a social event, ask me who I’m spending time with. Track that. Create a note with the person’s name as the title and “social” as the tag.
  • If I’m going to sleep, track that, then start tracking in Sleep as Android.
  • If I’m going to play a game, track that, then ask me what I’m going to do afterwards and how long I want to play. Load hints for the game (if I want). After the specified time, make a sound and remind me of what I was going to do.
  • If I’m going to read a book, show me the list of my checked-out books and let me pick one of them. Track that, then create a note with the title and author so that I can take notes.
  • NFC opportunities:
    • If I scan at the door, show me a menu: walk, subway, groceries, family, bike.
    • If I scan in at the kitchen table, track it as breakfast / lunch / dinner (as appropriate), then launch MyFitnessPal.
    • If I scan in at the table in front of the TV, show me a menu: relax, nonfiction, fiction, games.
    • If I scan in at my bedside table, treat it as going to sleep.

Mmm… Little things to tweak. =)

A deeper dive into absent-mindedness and misplacing things

I haven’t misplaced anything today, but I know I will at some point. This week? This month? Definitely this year, and probably more and more as the years go by. It got me thinking about misplacing things, and what I might be able to do about that.

When or why do I misplace things?

  • Active
    • Putting something down in one of many frequent places
    • Putting something down in an infrequent place
    • Getting distracted half-way and putting something down somewhere I don’t remember
    • Putting something down because my hands are full and I need to pick up something else
    • Putting something in a place that’s similar to but not the same as the place it should be, and not catching the mistake
    • Putting something somewhere near it should be instead of where it should be because that place is occupied or inaccessible
    • Putting something away for the long term, then forgetting where it is
    • Putting something away, then forgetting whether I have it or not
    • Putting aside something in progress or waiting for something else, then forgetting where it is or when I need to get back to it (ex: mismatched socks)
    • Shuffling things into similar things (ex: papers)
    • Making a mental note of where I put something, but not remembering it well enough
  • Passive
    • Someone moving or dislodging something from where I expect it to be
    • Forgetting to check for things that have accidentally fallen or been left behind (ex: gloves, scarves, things in pockets)
    • Leaving things in an opaque container for convenience, and then not taking them out and putting them away (ex: gloves)
    • Things falling out of pockets or through linings, un-noticed
    • Familiar tasks in familiar environments lead to automatic thinking and reduced attention
    • Forgetting to prepare or take something
    • Gaps when retracing steps
  • Retrieval
    • Skipping over something because something else is covering it or obstructing my view
    • Looking at something but not recognizing it
    • Limiting my field of view unnecessarily
    • Misremembering things that are similar to things I remember getting rid of, so I don’t look for them
    • Not searching in a systematic manner
    • Having a false memory of putting something away in a different place
      • Confusing with previous memory
      • Confusing plans with reality

What tools and tactics do people use to minimize the hassle of misplacing things?

  • Build automatic habits
    • Have one clearly defined place for each thing, or very few clearly defined places
    • Explicitly encode memories around picking things up or putting things down
      • Looking
      • Mental note
      • Note to self, out loud
      • Text note
      • Audio note, recorded
      • Picture
    • Have a handy holding place for in-between things or miscellaneous things, and review this frequently (ex: bin, belt bag)
  • Reduce retrieval costs
    • Regularly tidy with fresh eyes
    • Make lists of where things are
    • Label containers with their contents (ex: cabinets)
    • Keep things clear and tidy
  • Label
    • Label things so that in case they’re lost, someone might be able to return them to you
    • Offer rewards
  • Reduce the need for the item
    • Replace or supplement often-misplaced identification with always-present information or more frequently used devices (ex: biometrics, keycodes, smartphone)
    • Buy or budget for replacements (ex: pens)
    • Keep extra stock of items in multiple places (ex: pens)
    • Minimize the number of unneeded things you carry, and keep other things in a known place (ex: infrequently-used keys)
    • Eliminate the item entirely
  • Add alerts
    • Track location (ex: smartphones, parking)
    • Add proximity alerts (ex: smartphone-laptop Bluetooth proximity detection, tracking stickers)
  • Fill in gaps
    • Retrace steps
    • Ask someone else who might be able to look with fresh eyes or who might have different memories

When are these tools particularly useful?

From “External and internal memory aids: when and how often do we use them?” (Intons-Peterson and Fournier, 1986):

  • When intervening events may interfere
  • When there’s a long delay between encoding and retrieval
  • When accuracy is important
  • When information is difficult to remember
  • When there’s limited time to remember
  • When you want to avoid the effort of remembering

Based on these thoughts, what can I tweak about my life? Maybe I can pay closer attention to incidents of misplaced things and other action slips over the next few weeks so that I can see where the gaps are….