FLiFnotes

August 22, 2011

Purely Incremental Development

Filed under: Coding,Projects — Tags: , , , — Deborah Hawkins @ 8:17 am

Usually in incremental development there’s a plan which is subject to change as new features are added on incrementally and users have a chance to respond. For Flif Risc, I’m extending the idea to purely incremental development–a similar idea but without the overall plan. In purely incremental development, everything is subject to change. This may not be a great idea within a company where business justification is always necessary, but for a personal project it’s offers the flexibility needed to keep interest up.

Test-driven development goes hand-in-hand with any type of incremental development. Writing tests to define what you want to achieve in each iteration and then writing the code to pass them is exactly what’s needed to make regular process. As an added benefit, having the tests from previous iterations makes it easy to find out if a new feature’s implementation breaks existing functionality.

For unit testing in PHP, the natural choice in PHPUnit. At first, I had some difficulty getting PHPUnit set up from the installation instructions, but adding a sudo to the beginning of each instruction solved all my problems.

At the very basic level, I want my application to be able to take in a string which is the hex representation of a MIPS machine code instruction and output the instruction in assembly code. I’d like to accomplish this in a class structure, and knowing that the machine code for add $t1, $t2, $t0 is 0×01484820, the first test verifies that this is the result my code gives.

public function testGetAssemblyCodeAdd() {
    $input = '01484820';
    $expected = 'add $t1, $t2, $t0';
    $temp = new MipsInstruction($input);
    $this->assertEquals($expected, $temp->getAssemblyCode());
}

The easiest way to code this to make it work is to hardcode the output:

class MipsInstruction {
    public function __construct($machineCode) {
        // does nothing
    }

    public function getAssemblyCode() {
        return 'add $t1, $t2, $t0';
    }
}

Running phpunit on the one test now results in OK (1 test, 1 assertion), whoo! A commit is in order for this. Unfortunately, the code doesn’t do anything other than pass this one test, so the next step is to add a couple more tests:

public function testGetAssemblyCodeSub() {
    $input = '01484822';
    $expected = 'sub $t1, $t2, $t0';
    $temp = new MipsInstruction($input);
    $this->assertEquals($expected, $temp->getAssemblyCode());
}

public function testGetAssemblyCodeOr() {
    $input = '01484825';
    $expected = 'or $t1, $t2, $t0';
    $temp = new MipsInstruction($input);
    $this->assertEquals($expected, $temp->getAssemblyCode());
}

resulting in:

FAILURES!
Tests: 3, Assertions: 3, Failures: 2

Once again, I’m making these pass the easy way first and can improve the code later once I know it works.

class MipsInstruction {
    private $inst;

    public function __construct($machineCode) {
        $this->inst = substr($machineCode, -1);
    }

    public function getAssemblyCode() {
        switch ($this->inst) {
            case '0':
                return 'add $t1, $t2, $t0';
            case '2':
                return 'sub $t1, $t2, $t0';
            case '5':
                return 'or $t1, $t2, $t0';
        }
    }
}

Now that all tests pass, it’s time to commit and I’m ready to start refactoring.

August 21, 2011

The Origins of Flif Risc

Filed under: Projects — Tags: , , — Deborah Hawkins @ 7:19 pm

It’s easy to just lounge in front of the tv when you don’t have any projects to work on. It’s easy to sleep all weekend and to let blog ideas fade away. Getting started is the hardest part, though, and maybe if I can do that, it’ll make me that much more productive.

Step one: Come up with an idea

This was a project I was interested in doing while studying for Computer Architecture. It’s a simple web application that takes a MIPS instruction in machine code and then displays it in assembly code with details on the conversion. Honestly, the idea originated a semester earlier while learning the LC-3 toy language, and expanding the project to handle multiple languages is a possible future enhancement.

Step Two: Come up with a plan

The main reason I never really got started on this project before is because I always started with the architecture. I drew out diagrams of class hierarchies and debated the pros and cons of every possible design decision but never got to the coding part. To avoid this problem, this time I’m going with a pure incremental development approach and only a general overview of the desired end product.

As far as a technology stack, I’m using PHP mainly as a language refresher along with Git for my repository.

Step 3: Set up a repository

Subversion is my tried-and-true, so this is an opportunity to try another popular version control system that’s new to me. Fortunately, git has super easy set-up and hosting on github is free for open-source projects.

As everything is flif to me, you can find this project under the name Flif Risc. For now, it’s just an almost empty README, but it’s a start for things to come.

April 13, 2011

File Uploads over HTTPS with cURL

Filed under: Coding,Projects,UTCS — Tags: — Deborah Hawkins @ 9:27 pm

In some classes when we turned in a project all we got was a grade, but when I got a low score I could usually figure out what was wrong eventually. Working as a proctor in a computer science class for non-majors, though, the students could use a bit more feedback. The problem was, it was tedious manually uploading 75 comments files for each project since the only method of uploading was a web interface.

When I started as a proctor, I didn’t expect this problem. Upload scripts from previous semesters had been passed down and looked promising… but failed.

A quick look over the script was enough to identify the problem. The web addresses in the script were http:// when what I really needed to use was https://. The obvious solution was to update the addresses in the script, which of course still failed.

My next idea was to use replace the whole curl part of the script and instead use wget. However, wget doesn’t support multipart form data so that was another dead end.

At this point, I figured I was stuck using the browser, but maybe a Greasemonkey script would be able to perform bulk uploads. After all, it’s just adding extra forms to a page and submitting them. But no, modern browsers don’t let you auto-fill the path of file input in forms, which in retrospect makes complete sense.

So I was stuck with curl, which I was already able to use to set cookies or to fetch a page or text file. However, downloading zip files also wasn’t working. Time to look up the curl man page and just try anything:

  • Added -i to also include the headers for extra feedback
  • Added -referer, although no one in their right mind would rely on the referrer given
  • Added -A to specify Firefox as user agent, also dubious
  • Used -H 'Accept-Encoding: gzip,deflate' to attempt zip downloads
  • Changed the keep-alive settings

Nothing helped.

I switched between using the -d and -F flags to specify the content type, but only got Error - bad file data and 403 Forbidden respectively. One of these must at least be a step in the right direction, but which was it?

Finally, I figured out how to use --trace-ascii dump.txt to see exactly what was going on but didn’t know what to look for until downloading an HTTP analyzer for Firefox and using that for comparison. At last things finally started making some sense. As noted in a blog post from Ian Dennis Miller, an Expect: 100-continue header was also in the trace.

I added -H 'Expect:' to the command and it finally happened. I uploaded a comment file remotely. Halfway through the semester and finally some down time to get things working. Damn, I love Spring Break.

August 16, 2009

Getting started with Google AdSense

Filed under: Projects — Tags: — Deborah Hawkins @ 9:17 pm

A year ago, my AdSense application was denied because I had just started a new blog with only a handful of articles and they said my website was still under construction. This time I applied with my more developed hobby site instead and was pleasantly surprised with how easy it was to set up. (I modified the templates directly because I was too impatient to get a plugin working the way I wanted it to.)

After two whole weeks, I’ve earned a whopping $2.13! At this rate, I’ll hit my first $100 payout in just a short couple of years. Now I really wish I had applied again last year instead of putting it off; then I’d already be halfway there. Oh, well. In the end when it’s all averaged out, I’ll have made just enough to cover my hosting costs which makes this a no-cost hobby. There’s nothing better.

July 17, 2009

bbPress 1.0 is finally here!

Filed under: Projects — Tags: , — Deborah Hawkins @ 1:44 am

Hive Bee Honey
Whoa! Two and a half months since my last blog, but bbPress 1.0 just came out recently and I updated the Chavez360 project with this and WordPress 2.8.1, and I finally have a site that integrates as smoothly as I’d like. The only really important suggestion for anybody about to set this up is to install WordPress completely first, including the new bbPress plugin before going on to the bbPress installation. The process would have been a tad smoother for me if only I had thought to do that.

April 4, 2009

Damn Spammers

Filed under: Projects — Tags: , , , , — Deborah Hawkins @ 6:06 am

In the past few days, I’ve received about 25 emails from my blog to moderate spam comments–all obviously from the same idiot spambot. So I can understand now why the default option is set to send email notifications to the blog administrator. Even if the comments aren’t posted without moderation (by default), that administrator still needs to know what is going on to find some other method to keep these spam comments from getting in their way.

Since Akismet (I can never spell that right) is built into WordPress, the first thing I did was to activate it and see how that worked. Fortunately, on the Akismet configuration page is an option to “Automatically discard spam comments on posts older than a month.” That’s wonderful! The post that that bot keeps trying to comment on is over two months old. Why didn’t they make this option more obvious so I could’ve signed up sooner? Well, I can’t really complain. I just have to sit back now and make sure this works….

Update: it works! So many spam comments caught. Akismet, I love you!

March 25, 2009

Choosing bbPress / WordPress

Filed under: Projects — Tags: , , — Deborah Hawkins @ 2:57 pm

My pet project has undergone many changes in the past several years. What started as a 20 pages of HTML on a free webhost in early 2005 has developed into over 150 pages of content with a news blog, forum, and gallery. Back in 2005, though, I had a lot of free time on my hands. For a while, there was even a wiki for my content. That had been my original idea behind using Chavez360 as the site name: if you followed links around the site, eventually you’d link back to where you started from. But that seemed to be kind of overdoing it, and at the time I couldn’t figure out how to integrate the wiki membership with the rest of my site.

What I had just wasn’t working as planned. As I learned more about webdevelopment and coding, I more and more wanted to create a new CMS and forum from scratch so I could have exactly what I wanted. Unfortunately, it was a needlessly complex task, and it took well over a year before I realized that I wasn’t going to create anything that I’d be satisfied with anytime soon. So I started looking around. There were big CMS’s, blog software, forum software, all in several languages and with a huge variety of features available. How to decide which was the best for me? I wanted something:

  1. simple–something that wasn’t already bloated with features that probably would never get used and something where I would at least understand most of the source code. This was probably the strongest factor in my choosing bbPress. By default, it has only the most basic functionality, and anything else can be easily added to taste with plugins.
  2. clean–not just the code, but the actually look and feel of the forum pages. It’s easier to find what you’re looking for quickly when it’s neatly organized and not cluttered with lots of unnecessaries.
  3. with a community–okay, so maybe the bbPress community isn’t that large, but the WordPress community definitely is. Between the bbPress forums and the WordPress codex, I can find anything I’m looking for.
  4. fresh–not so old that everything you could possibly do with it has already been done. I’m looking forward to making a couple of plugins available for others to use… eventually.

It may be weird to choose bbPress first and then WordPress also for consistency, but so far, so good.

March 24, 2009

Moving to WordPress / bbPress

Filed under: Projects — Tags: , , , , — Deborah Hawkins @ 7:42 pm

After many months of planning and procrastination, I finally used Spring Break to move my site from plain php for content and SMF for the forum to WordPress with bbPress. As much effort as it took, I have to say that either it was much easier than other conversions and integrations I’ve experimented with or the experience from those previous experiments has really paid off.

For the most part, I followed affacat’s instructions on his successful convert from SMF to bbPress, trying it out first on my own machine of course before ready to go live:

  1. Install bbPress 0.9.0.4 and WordPress 2.7.1. I chose to put bbPress in a subdirectory of WordPress. Set up the database integration as part of the bbPress installation and delete any posts created on install.
  2. Install the latest phpBB with the necessary converter to move my existing members and posts to bbPress.
  3. Install Jaim’s phpBB to bbPress converter. I had to change bb_users to wp_users, and delete the first user and forum from the SQL because there are already a first user and forum in bbPress. I’m not sure what the topic_resolved key was from, so I removed that option. Then I copied and pasted the code from bbPress into this tool to generate my topic and username slugs. (There may have been other changes also that I didn’t keep track of.)
  4. Finally, I imported the SQL into my database.
  5. Install and activate SuperAnn’s WordPress plugin for WordPress / bbPress cookie integration.
  6. Activate other plugins.
  7. Post the first blog entry and new forum thread to announce the updates.

Man, it feels good to finally have the base I need to build up my site.

Powered by WordPress