Crow Divination 2nd in Search Results
I came up with the idea to make a program for divining crow cries from jcrow’s. With slight modifications over time, it has come second to the original source of information.
I came up with the idea to make a program for divining crow cries from jcrow’s. With slight modifications over time, it has come second to the original source of information.
While working on the tree part of the coursetree project, I ran into the question of how to display the course dependencies. I have written a recursive function that returns a recursive list of course prerequisites:
I wanted to turn it into a diagram of course prerequisites and decided 2 flat lists could retain the data:
For example,
and
We start off with a recursive list representing the tree structure:
To tackle the problem, I first solved a similar one: flattening a list.
This can easily be done in Scheme, as syntax and type declarations do not get in the way.
Here’s the same code translated into Python:
Unfortunately, flatten in Python produces a hypernested structure for flat lists, as (1 2 3) in Scheme is equibalent to (cons 1 (cons 2 (cons 3 empty))) or (1 . (2 . 3)).
The more serious problem is that it exposes a quirk in Python:
Yes, that means the list disappears after being extended with an empty list . . . one of those unpleasant surprises.
So let’s redefine a flat list in Python:
There is a similarity between this approach and the recursive one: different actions are taken for a list node and other nodes. I used a combined functional and imperative approach to solve the problem:
We start off with a recursive list representing the tree structure, slightly different from the list for separating the levels:
Again, a mix of recursion and iteration easily solves the problem:
Hopefully, you’ve had fun reading this article and meanwhile came up with a better way to represent the tree as a flat structure.
I’ve had the idea of making a self-updating, navigable tree of Waterloo courses. This is the first step. (Actually, not the first step for me. It started with Django, which had to do with my last work report’s comparison to Zen Cart. Some credit goes to Thomas Dimson for inspiration. He made the Course Qualifier.) The main idea for this step is to gather all the information to be stored in a database. With that (the idea and plan) begins the coding phase:
I wanted to gather the course (“SE 101”), name (“Introduction to Methods of Software Engineering”), desc (“An introduction …”), prereq (“Software Engineering students only”), and offered (“F”) each as separate fields
In order to do that, I wrote a spider to crawl the page:
There are several things to note:
Finally, the spider pipes its results to an output format. CSV format meets the requirements, as it can be inserted into a database.
Two gotchas:
This part of the project was done in 2 hours with Scrapy. The project can be found in the downloads section.
Recently, I was assigned to fix bugs on a large project done by 2 previous co-op students. I came across the Debugging section of Steve McConnell’s Code Complete 2 while looking up maintenance in the index. He suggests using the scientific method, summarized here:
I applied this to a recent debugging problem. The bug is as follows, reported by a tester:
Then used the Prev Next button to goto the next page and forgot to save the previous data.
Can there be a warning you have unsaved data before I lose this.
this should be for everyone student/employer/staff that enter data.
I started by trying to understand the problem, which I interpreted as:
Understanding the problem in terms of the business goals of the application opens up many possibilities, I chose to make the next and previous buttons save the input and take the user to a different page. This is where the debugging begins. First, I checked the HTML output for the save button and looked up its id in php scripts using grep. Finding the correct place to edit the code was easy. Making the right modification was the hard part. The code looked like this:
Fortunately, I knew enough Javascript and functional programming to understand what the code was doing, but only on the surface. When the button is clicked, the function is executed. It sets a hidden form field to submitted status so that php stores the input in the database. So I wrote what looked like innocent lines of code:
It worked immediately in Firefox. I thought I was done. Next, I got a report from one of the testers that it did not work for them. I tried it again in IE with the expected result. At this point, superstition came into play. I had previous experience with IE where a javascript error prevented an independent section of code from working. I hypothesized it could be the if statement, because it may not be allowed with jQuery. I tested my hypothesis by taking out the if statement. As no progress was made, I checked the error console in Firefox. It gave an error about $(‘#next’).click on object which does not exist. So I moved the script down below the area where the next link was created. It still did not work in IE. I decided the brute force approach was to learn jQuery and understand exactly what the code was doing. The tutorial was surprisingly short. I made sure my code used the correct jQuery syntax. When I read the documentation on the click method, an idea came to me that IE went away from the page without executing the registered event. There was other evidence supporting this hypothesis in Firefox, clicking next rather than save took many times longer. At this point, I doubted mousedown would work, as I already tried onclick. Luckily, I did look up documentation on mousedown. It looked like it was the correct way to prove or disprove my hypothesis. Switching from click to mousedown did verify my hypothesis. To my surprise, hitting next saved data in IE, with the same speed as hitting save.
I asked a question on probably one of the higher traffic forums, and it was answered within an hour. It still took 3 people to put together the answer because one line of code couldn’t work without the other. I had to have about the same level of technical knowledge to make use of the information and ask the question. What made this answer question style different was that the question was answered immediately unlike some other forums I’ve used. You can see it for yourself here:
Python FTP Most Recent File – Stack Overflow
Coincidence? It was on this website that I first heard of dive into python, the online book I used to learn the language. Except I learned dive into python 3 and asked the question from Google. A lot can be said about the use of the democratic process where knowledge matters.
While working on a word search generator that translated letter symbols (sort of like cryptograms, except this one’s impossible to solve without the key), php ran out of memory on a rather ordinary function.
Now I understand why there is a need for a lower level implementation of UTF-8 strings by default in php 6. Python support of UTF-8 support has already been included in Python 3.0 released December 3rd, 2008.
If you ever wanted to include PEAR.php in a script, but never installed it before on a shared host, a google search for pear.php download should have solved the problem. On the contrary, following the first links on google is a huge waste of time. In my situation, I only needed pear.php to instantiate a class. The intuitive solution is to just download the file and ftp it to the same location as the file that includes it. That works, except the official installation guide never says that.
There’s a handy feature in Notepad++ that’s not enabled by default.
This works on Windows 7 or Vista, but the pop-up window blinks. Here’s the way to enable it:
On another note, you can make it load faster by adding the -noPlugin flag to it: