Posts tagged “educational”
Kip Password tips for non-geeks

I’ve been thinking about passwords recently, as I have gone and changed passwords for pretty much every website that I can remember having a password for. For me, this was prompted by the hacking of PlayStation Network, which led to my PSN password being compromised. And, like most people, I used the same password for PSN that I used for many other sites. This is generally a Bad Thing, but what are you going to do?

Well, for geeks, the answer is “have a separate, randomly-generated password for every site, and the password must be long and contain numbers, lowercase letters, uppercase letters, and symbols.”

I realize that this is impractical for normal people.

So here’s my advice for non-geeks. Come up with a sentence. A really random sentence. Try to include some numbers in the sentence. Then take the first letter of each word. This will be your base password. Here, I’ll make up an example:

forget about the last 7 things u Heard 2-day

That gives us: fal7tuH2d

Believe it or not, it’s really easy to remember a sentence like this! You can leave out articles, conjunctions, and/or prepositions if you like, and you can replace “are” with “r”, “you” with “u”, etc. Whatever is most natural for you to remember. Making at least one of the letters uppercase and including some kind of punctuation is good. Make sure there are at least 7 characters, since a lot of sites use 8 characters as the minimum length of a password.

Next, come up with a rule for how you will include the company name in the password. For example, “use the last letter of each word in the company name, and capitalize the last one”. Using this rule, my password for Amazon, PayPal, and Gmail might be as follows:

Amazon: fal7tuH2dN
PayPal: fal7tuH2dyL
Gmail (Google Mail): fal7tuH2deL

Now, if someone somehow obtains your password to one site, they won’t have your password to every site you use. And hopefully they won’t be able to figure out the rule for the last few characters (this is why using something other than the first character of the site name is a good idea). And no one’s ever going to guess a password like that.

Of course, this isn’t fool-proof. But it is a lot more secure than using the same password for every site, and it’s a lot more secure than using a word that can be found in a dictionary or your pet’s name or your birthday or something like that.

Note: If you really want to do it the geeky way (a long, random password for each site), you can get applications that will generate random passwords and store them securely. This makes it so you only need to memorize one password, and that password lets you access all your other passwords. I like KeePass, and it runs without an installer on PC and (I think) Mac. I keep it in my Dropbox so I can use it from home or work. But I don’t do it for every site; mainly, I just do this for really sensitive sites (like bank and credit card websites). And remember, if someone really wants your password, they can probably crack it in a few hours with just five dollars of equipment.

No Comments
Kip Joining together for better queries

Here is a tip for writing better SQL queries—specifically, the FROM/WHERE clause.1 I only work with SQL Server and MySQL, so the syntax may be different in different engines.2 I’m writing this because I often see very smart and experienced developers write some downright ugly SQL. I don’t mean to call anyone out; I just want everyone to know there is a better way of joining.

Rule of thumb: If you have a comma in your FROM clause, you’re doing it wrong.

Let’s take a query I just made up as an example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
SELECT AVERAGE(Grades.score)
     , Departments.Name
     , Students.Gender
FROM Students,Grades,Departments,Teachers,Courses,Classrooms,Buildings
WHERE Students.id = Grades.Student_id
  AND Courses.Period = 3
  AND Courses.id = Grades.Course_id
  AND Buildings.Building_id = 11
  AND Classrooms.id = Courses.Classroom_id
  AND Buildings.id = Classrooms.Building_id
  AND Grades.Grade > 0
  AND Teachers.id = Courses.Teacher_id
  AND Departments.id = Teachers.Department_id
GROUP BY Departments.Name, Students.Gender

So what’s so bad about this? First of all, it’s tricky to see what exactly we are trying to do here. The WHERE clause is huge, and it’s full of stuff that isn’t really relevant to what we are trying to return. If you were told that this query was returning the wrong values, you would have to stare at it for quite a while to figure out what’s going on here. You know what tables the data is coming from, but you don’t have any simple way to tell how those tables relate to each other. You have to reverse-engineer that information from the monster WHERE clause.

And here is where developers are most likely to mess up: if you forget just one of those AND predicates in the WHERE clause, you end up with a cartesian product. This means if one table has n rows, and another has m rows, you will get n×m rows. This is pretty much never what you actually want. If the developer is working on a small database, with very little data3, he might not even realize this is happening. He checks in his code, and goes on to the next problem. But then the system goes into production, and the tables get a few hundred rows each, and now the query runs for twenty minutes and then the database server crashes! Ouch.

So, what’s the solution? Like I said, if you see a comma in your FROM clause, you’re doing it wrong. JOIN to the rescue!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
SELECT AVERAGE(Grades.score)
     , Departments.Name
     , Students.Gender
FROM Grades
JOIN Students    ON Students.id = Grades.Student_id
JOIN Courses     ON Courses.id = Grades.Course_id
JOIN Teachers    ON Teachers.id = Courses.Teacher_id
JOIN Classrooms  ON Classrooms.id = Courses.Classroom_id
JOIN Departments ON Departments.id = Teachers.Department_id
JOIN Buildings   ON Buildings.id = Classrooms.Building_id
WHERE Buildings.Building_id = 11
  AND Courses.Period = 3
  AND Grades.Grade > 0
GROUP BY Departments.Name, Students.Gender

In this version of the query, we JOIN each of the tables together in the FROM clause. This has several advantages, but the biggest by far is that it forces the developer to specify how the tables are joined together. This makes it extremely difficult to accidentally create a cartesian product. It also cleans up the WHERE clause, stripping it down to conditions you are actually filtering on. In this case, we are just looking at third-period courses in some particular building where students are at least attending the class. Whenever I make a change to an existing query that doesn’t use joins, I usually rewrite with joins. I’ve done this for dozens of queries, and the WHERE clause is reduced to a single statement probably 80-90 percent of the time. This makes the query much easier for the next developer to understand at a glance, especially since the join conditions aren’t likely to change over time. As far as performance goes, there is a slight benefit because you’ve already told the database how the tables are joined together. But the database was already figuring this out on its own, so there’s not much of a difference. But it certainly doesn’t perform any worse.

Update 4/18: I forgot to mention one other benefit of this approach. There is a type of error that comes up every once in a while looks something like this: “This query doesn’t return online courses because Courses.Classroom_id is 0/NULL for online courses.” This is easy to solve with joins. Just change the “JOIN Classrooms” clause to “LEFT JOIN Classrooms”. I’ve seen some ugly code that tries to accomplish the same thing with UNION. Union is worse for performance than left join, and left join is specifically designed for this purpose.

1 I already know what ORM is. Some of us are working on code that doesn’t use ORM and we can’t do anything about it.
2 As I recall, this works in DB2, but I haven’t used it in 2 years. It works in Access if you replace JOIN with the more explicit INNER JOIN. And I’m pretty sure Oracle uses some other kind of crazy syntax. Edit: I’ve been told Oracle supports the same syntax.
3 Bad development practice, but don’t pretend like you’ve never done it.
Kip Storyteller

Over Thanksgiving weekend I had the opportunity to learn two new parenting tips. First: if kids want you to read them a story and you don’t have a book handy, just make one up. Second: kids have no idea when you’re plagiarizing.

I shared a story with Emma and her cousins that went something like this:

Once upon a time there were three astronauts who wanted to go to the moon. But when they went to the doctor, he told one of them “you can’t go to the moon because you’re getting sick!” And he said “no way!” but it didn’t matter, so they had to get another guy to go to the moon with them. Then when they got halfway to the moon part of their ship blew up and they were like “oh no!” and they got on the phone and said “Houston we have a problem.”

Kip While I’m at it: How to win at the Cracker Barrel peg game

In my last post I discussed the game of hangman, aided by an algorithmic analysis of the winningest words. A few months ago I did something similar with the peg game they have on the tables at Cracker Barrel.  The one where you have a triangle with 15 pegs, with one missing. You remove a peg by jumping over it. The goal is to leave only one peg remaining. I think I won the game the very first time I ever played it, and I don’t think I’ve won since then.

It occurred to me that the game would be easily solved with brute force, and after an hour or two of coding I had done so. However, I never went much farther than that. I had hoped to look for patterns or simple rules that lead to a victory, but never really got very far. But I decided to post what I have here just for the sake of doing so.

         0
       1   2
     3   4   5
   6   7   8   9
10  11  12  13  14

Given the above peg positions, there are four unique starting configurations: you can start with peg 0, 1, 3, or 4 removed. Any other position is a mirror and/or rotation of those four. So I looked at which starting positions were the most likely to win.

Peg 0: 29,760 ways to win of   568,630 games (5.23%)
Peg 1: 14,880 ways to win of   294,543 games (5.05%)
Peg 3: 85,258 ways to win of 1,149,568 games (7.42%)
Peg 4:  1,550 ways to win of   137,846 games (1.12%)

So the moral of the story is: start with a middle edge peg removed, not the traditional configuration of top peg removed. Beyond that, I got nuthin.

No Comments
Kip How to win at hangman

Last week Stephanie and I were discussing the game of hangman. I commented that “rhythm” and “myth” are good words because the only vowel is y, and most people try to find the vowel first. I wondered what might be the best possible words.  When I remembered that I’m a programmer, I said “hey, I can write a program to figure this out!” And since I haven’t posted on this blog in quite a while, I thought I’d share.

I found a list of 58,112 words and got to work. I decided to first count the frequency of each letter in the word list.1 I figured that the probability that a letter would be guessed is approximately equal to the frequency of that letter in the language. This could be a bad assumption, but it’s all I had to work with. Then I computed a score for each word by averaging the frequency of each letter in the word. I don’t know that this is the best way of measuring the difficulty of the word, but it’s the best one I could come up with.

Here are the words with the lowest scores (and therefore the most difficult hangman words, according to my algorithm):

fuzz     1.28%
fuzzy    1.37%
buzz     1.39%
why      1.57%
by       1.79%
jazzy    1.95%
jazz     2.01%
huffy    2.02%
buff     2.03%
huff     2.10%
jug      2.17%
jumpy    2.18%
puffy    2.18%
my       2.20%
hubby    2.20%
muff     2.23%
jump     2.29%
puff     2.29%
buy      2.33%
foxy     2.36%

And here are the easiest:

see     10.55%
eerie   10.15%
ere     10.13%
nee     10.08%
sees    10.05%
tee     10.04%
ease     9.81%
eire     9.79%
seer     9.73%
seen     9.69%
eerier   9.67%
tees     9.67%
serene   9.60%
eases    9.56%
settee   9.54%
lessee   9.54%
eel      9.52%
seine    9.52%
seers    9.50%
eeriest  9.47%

While I was at it, I did some other searches on the word list.  Here are the 49 words that have no vowels besides Y:

by
cry
crypt
crypts
cyst
cysts
dry
dryly
fly
fry
glyph
glyphs
gym
gyms
gypsy
hymn
hymns
lymph
lynch
lynx
my
myrrh
myth
myths
nymph
nymphs
ply
pry
pygmy
rhythm
rhythms
shy
shyly
sky
sly
slyly
spry
spy
sty
styx
sylph
sylphs
sync
thy
try
why
whys
wry
wryly

Seventeen words contain all the vowels, including Y:

consequentially
counterrevolutionary
disadvantageously
facetiously
gregariously
heterosexuality
homosexuality
neurologically
neurotically
pertinaciously
precariously
precautionary
questionably
revolutionary
simultaneously
supersonically
tenaciously

And only two words contain all the vowels, including Y, in order:

abstemiously
facetiously

1 This is slightly different from the frequency of each letter in the English language. For example, “t”, “h”, and “e” probably have higher probabilities in the English language than in the word list, since “the” is used over and over in the language, but it is only represented once in the word list.
No Comments
Kip Pronouns are hard

I’ve never thought deeply about this topic before I had a child in the process of acquiring this mangled mess of words we call The English Language... but pronouns are hard you guys!

We sometimes ask Emma who different people in pictures are, so that she can remember the names of those family members she doesn’t see every day. When we get to a picture of Emma, we’ll say “Emma, who’s that?”

“Baby,” she’ll reply.

Then we will say “Emma, that’s you!”

At least, that’s what used to happen. After doing that for some time, if we ask Emma who is in a picture of Emma, she’ll now respond “you!!” And really, that’s our own fault. We told her that it was a picture of You, and so she learned who You was. Apparently You is a baby who looks suspiciously like Emma.

We could try to correct her by telling her it’s “me,” but won’t that get confusing when she actually does learn pronouns? She’ll wonder, “Why did mommy and daddy say that picture of me was a picture of them?” So I guess for now we’ll have to teach her “that’s Emma.” We’re also working on the whole you/me thing with finger pointing, but I’m not sure if it’s too advanced for a twenty-two month old.

Or maybe I could just try explaining that my “you” is your “me” and your “you” is my “me.” There’s nothing confusing about that, right?

No Comments
Kip Regional dialects and vowel shifts ruin poetry

Lately we have been getting Emma into a bedtime routine.  Ostensibly, this is to teach (condition?) her into going to sleep easily at night, provided the routine is observed.  In actuality, she doesn’t go to sleep much more consistently than before the routine.  But that’s not really what I came here to write about.  Part of Emma’s bedtime routine is for daddy to read her a story.  (Literacy for the win!)  Tonight I tackled Horton Hears A Who, one of her two Dr. Seuss books (which are by far her longest bedtime stories).  I noticed while reading the book that Dr. Seuss must have pronounced “mayor” as a one-syllable word, a homophone to “mare,” whereas I pronounce it as two syllables, rhyming with “conveyor.”  I’m not sure if I pronounce it differently because I live in a different region, or because the pronunciation has shifted since the book was written in 1954, or both.  (Contrary to what your grade school teachers probably tried to burn into your head, English is a constantly evolving language, and the accepted pronunciation and even meaning of words varies by region and changes over time.)

Here is an example of what I’m talking about from Horton Hears A Who:

There aren’t any Whos!  And they don’t have a Mayor!
And we’re going to stop all this nonsense!  So there!

And here is one more example, which is even odder to my ear:

“So, Horton, please!” pleaded that voice of the Mayor’s
“Will you stick by us Whos while we’re making repairs?”

It is weird to read because “mayor” is used for a rhyme several times in the book, and if I read it so that it doesn’t rhyme it sounds really weird.  In fact, I tend to pronounce the word that is rhymed with mayor (i.e. “there”) as two syllables.

I guess I’m not really going anywhere with this, it was just something I noticed and thought I’d point out.  Other than mayor/mare thing, I didn’t notice any other rhyming problems.  In one place, I think “grocery” must be pronounced as a three-syllable word in order to have the intended rhythm, although I (and most people I know) typically pronounce “grocery” as something like “groshry.”  Oh well, people still consider Shakespeare great poetry, even though many of his rhymes no longer rhyme, so I guess it doesn’t necessarily spell doom.

Kip Organic milk has a ridiculous shelf life

Over the weekend—while I was back home for my brother’s wedding (some pictures will likely come soon)—I noticed that the organic milk my mom has started buying has a really long shelf life.  The carton I was pouring milk from, for example, didn’t expire for well over a month.  I was curious why this was the case so I did a little research and it seems that this milk has been treated with ultra-high-temperature (UHT) processing, rather than regular pasteurization.  From what I’ve read on Wikipedia, it seems that UHT milk could actually sit at room temperature for months without going bad, and in Europe it’s actually sold unrefrigerated.  Apparently they sell it refrigerated here because Americans wouldn’t buy unrefrigerated milk in test markets.

I couldn’t find a consensus as to why organic milk is UHT processed, though.  Some people said it was because “organic cows” aren’t given antibiotics, so UHT must be used to be sure all bacteria are killed.  Another said organic milk is typically shipped from further away, so they have to use UHT or it would be about to expire by the time it got to the store.  I’m not sure which is the real reason and I don’t feel like doing any more research.

Anyway, I thought that was an interesting fact I’d share with the class.

No Comments
Kip Myth busting

Some astute individual has probably told you at some point that Eskimos have dozens of words for “snow,” whereas English-speaking individuals only have one.

They lie! (Warning: link goes to a PDF file.)

Also on Wikipedia.

No Comments
Kip Many moons to come

I found this today and thought it was kind of neat.  Many northeastern Indian tribes had names for each of the full moons every year.  Here is a list of the named moons for 2008.  First up is the Full Wolf Moon, next Tuesday.

Maybe everyone else has heard about this, but I never had so I thought I’d share.  It also seems like a great idea for an elementary school teacher to have a little party for the class for each of the moons, while teaching the kids about Indian culture.

No Comments
RSS feeds: Kip's - Stephanie's - Both