A Foolish Manifesto

fREWdiculous!

Concert of the Month: Bat for Lashes

Last night (Thursday) I saw Bat for Lashes live. It was a really good concert!

You may have heard about Bat for Lashes from their awesome, creepy music video from 2007.

I got the album (Fur and Gold) after hearing that song and was mostly disappointed. The other songs just didn’t seem to have the depth and feel as that song. So then recently this year I heard Daniel on Last.fm.

Very cool song! Especially when you realize what it’s about!

Wes: Khan said in an interview with The Sun newspaper that Daniel was based on a fictional character that she fell in love with as a teenager.

she fell in love with daniel-san?

The Karate Kid! So then I got that album (Two Suns). It was better than the first one, but I still wasn’t feeling it.

Well, last night I convinced myself to see the show because the band makes such good music videos that the show could theoretically be really great. Well fortunately I was right, objectively speaking!

The whole band was spot on with sound. The main thing that I noticed was that the synth was weirder and the drums and bass were louder, giving them that sound I’d always hoped and dreamed for. I have a theory that when the band records, the label (presumably) turns up the sound on the singer’s voice, makes the synth mostly chill, and relegates the D&B to the background so that the music will be more palatable to the masses. I haven’t done any research at all on this, but I can say that their performance was great live, and their albums are mostly mediocre (to me).

My only complaint was that the concert was at The Loft, which is part of The Palladium. The Palladium has bad sound, is in a sketch part of town, and is just bad in general. Here are some examples comparing The Palladium to The Granada (my favorite venue of all time.)

  1. The Granada, while small, has multiple floor levels, so you never get stuck behind tall people. The Palladium is flat.
  2. The Granada has a bar, but it’s well partitioned from the concert area, so the annoying loud drunk people don’t spoil the show. The Palladium, not so much.
  3. The Granada has a dedicated photographer who will email (and post on flickr) any pictures he takes of the show. With the Palladium that’s not the case, so when you are trying to watch the show you see annoying people taking pictures instead of watching the show.

Overall though, I’d give the concert 4 stars; and it would be 5 if it weren’t at The Palladium.

  • 0 Comments
  • Filed under: Uncategorized
  • Finding a sweet domain with perl

    So yesterday I spent a few hours trying to find a cool domain for the project I am working on in my free time. (By the way, raptorprey.com is open.) After looking at lots of various options, I decided that it would be really cool to get a domain of a latin work with the .US TLD. Too bad I don’t know latin right?

    (I can't read this)

    (I can't read this)

    So I went online and found some cheesy one page latin dictionary that had a few thousand words. I used vim to clean up the data (after saving as plain text) and turn it into a standard format (JSON.) Next I used vim to filter out all the words that didn’t end in us. To do that I used a command something like the following:

    1
    :g!/^".*us"/d

    That will find all lines that have words that don’t end in us, and then delete them. Then I wrote a perl script which would do it’s best to read in my serialized data, check if the domain was available, and store whether it was or not. Here’s a permutation of it (I changed it a lot and I left out the domain checking, as that’s technically Against The Rules):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    #!perl
    use Modern::Perl; # just for one-off's in my mind
    use JSON;
    use File::Slurp; # again, just for a one-off

    my $file = shift;
    my $text = read_file($file);
    #format:
    #my $final_data = {
    #   unchecked => \%new_data,
    #   possible  => [],
    #   unpossible => [],
    #};
    my $final_data = from_json($text);

    foreach my $domain (keys %{$final_data->{unchecked}}) {
       warn "checking $domain.us";
       # MAGIC HERE
       if ($exists) {
          push @{$final_data->{unpossible}}, "$domain.us";
       } else {
          push @{$final_data->{possible}}, "$domain.us";
       }
       delete $final_data->{unchecked}->{$domain};
       sleep 1 + rand();
    }

    END {
       my $json = JSON->new->pretty;
       say $json->encode($final_data);
    };

    I have the end block doing the final output because something was killing the program, even if I put an eval around that part of the code, so what I did was basically output the same format that I input. That way I could just manually edit the data that was causing the issues.

    Cool huh?

  • 5 Comments
  • Filed under: Uncategorized
  • Metrics + Debug!

    The project I am working on at work is going to be deployed soon, so today I worked on some of those things that need to be taken care of before the deploy. One of those things was changing our gigantic list of javascript files into a single file with minimal hassle. I actually tried to implement it myself, but that was silly. A simple search on CPAN for catalyst javascript yields two promising results.

    The first is Catalyst::View::JavaScript. While this is an excellent package which does caching and automatically minifies depending on whether the server is in debug mode or not, it expects javascript to be in memory already. Maybe that’s something that’s common and I don’t know about it, but we almost never write javascript on the server.

    So onto the next result: Catalyst::View::JavaScript. It does not do caching, and it always minifies. But heck! That’s not too bad. Before installing it, note my RT that it does not have correct dependencies. Hopefully that will be fixed soon. I also sent another RT. Since I technically write more lines of javascript than perl, I need to be able to turn off minification. So I patched the module to only minify when the server is not in debug mode. Hopefully that will be accepted as well.

    So after doing that I ensured that apache had gzip turned on to reduce the amount of bandwidth required by the clients to download our javascript. Then I got curious. How much of a difference do these things make? So I measured it:

      no gzip gzip
    no minify 807K 212K
    minify 712K 202K

    Wow! Minification really doesn’t help that much, whereas gzip’ing is huge.

    Now, just to be clear, this isn’t a great solution for an externally facing site, because the clients don’t currently cache the minified javascript, because it gets served by Catalyst and it’s probably not worth my time to set that up all the headers to fix that for a site that runs mostly on a LAN. Once the customer does start allowing external access we’ll want to set some last-modified headers and whatnot.

    I also did a few more cool tweaks using debug mode. For example I have the debug version use ext-all-debug.js, which has extra stuff for error messages and whatnot, and ext-all.js, which is preminified and has error checking removed for performance reasons (for the tests above I used ext-all.js the whole time.)

    Furthermore I have the debug switch my server side error messages from actual exceptions to a simple message asking the user to get in touch with the devs and tell us what happened and what time it was when it happened.

    All in all I felt really good about the code I wrote today. It will help me a lot as time goes on and it makes the dev server way faster (1 small download is way faster that 60~ really small ones). Too bad the customer will probably not notice a significant amount of it :-) Anyway, hopefully these tips will help give you some ideas for your webapps.

  • 2 Comments
  • Filed under: Uncategorized
  • Perl 6 in Perl 5 FOR THE WIN

    Today I wanted to generate a list from another list. Typically I would use map for this, but I wanted to iterate over two elements at a time, instead of one at a time. (A lot of people said to use natatime from List::MoreUtils, over and over. They didn’t read my question very carefully, especially since I specifically said I wanted natatime but with map.)

    Anyway, mst pointed out Perl6::Gather, which works perfectly for this situation! Ah the beauty of Perl 6 in Perl 5. Here are the codez:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    my @list = (
      foo => [qw{bar baz biff}],
    );

    my @new_list = gather {
      while (my ($foo, $bar) = splice(@list, 2, 0) ) {
         take map { "$foo/$_" } @list;
      }
    };

    So basically what that does is create an implicit accumulator and every time you call take it adds the arguments to take to the accumulator. In Perl 6 map can iterate over multiple items at once, so this would be silly in that context, but in Perl 5 it’s quite helpful!

  • 0 Comments
  • Filed under: Uncategorized
  • The Beauty of Code Reuse

    I’m probably preaching to the choir here, but it must be said: code reuse is most excellent!

    Today I got a somewhat complex feature working for our customer, and almost all of it was features I’d already written, and due to the organization of our system I could easily reuse most of the code.

    Our customer fixes airplane parts. When they fix a part they need to document every single thing they did to the part. We have each operation (more or less) that can be done already defined so that they can at least save those keystrokes (they are actually operation templates.) But there are a lot of operations and a typical work order will be around 50 operations, so choosing the same operations over and over is a waste of time. So we have a feature that lets them look at other work orders that were fixing the same type of part and copy operations (and materials) from that.

    It was really easy to use the existing view for operations and materials because the front end is entirely comprised of JS classes. I even used an instance of the work scope grid to list all of the work scopes that are for the given part. The nice thing was that so far I’ve written no new server side code yet. And for the classes I didn’t use inheritance; I used a role style object modification by doing what Moose people would see as an after method on new (called a plugin in ExtJS). With the plugins I could simply change the store to ask for a given part-type’s work orders, hide extra columns, and add listeners to update the operations and materials when a user clicked a row.

    Don’t think this is all just JS praise; Perl and Catalyst were help too. But really the benefit here was the use of any web framework in general. Because I’m using a framework I can easily find server side actions that do what I need (which the grids were already tied to in their base classes, but still.) In our other projects I’d be hard pressed to give you a list of all of our “actions,” whereas with CGIApp I can easily make a list of runmodes myself, and with Catalyst the server will make a list for me.

    Excellent!

  • 0 Comments
  • Filed under: Uncategorized
  • CPAN Ratings Day

    You may have noticed that there really aren’t a lot of CPAN Ratings out there currently, but you have a chance to help that. The past couple of weeks I’ve done two or three CPAN ratings every Thursday. Just go to CPAN Ratings, get an account, and rate modules that you are a fan of.

    Generally criticizing modules in active development is a bad idea since bugs should really go to rt. But if the module is “done” and there are bugs, a bad review might be feasible.

    Anyway, Happy CPAN Ratings day!!

  • 2 Comments
  • Filed under: Uncategorized
  • Dallas.p6m: August 2009

    So we had another Dallas.p6m tonight. It was fairly laid back compared to some other ones, but it was still a lot of fun.

    I did a “talk” on the Perl 6 object model, which I didn’t prepare enough for, so it was mostly me asking Patrick some basic questions about stuff I could relate to Moose. So here is the skinny on that stuff:

    has in Moose is a method, that ties a string to some attributes.

    has in Perl 6 is actually the OO version of my. So you do the following:

    1
    2
    3
    4
    # generate method getters and setters and $!foo
    has $.foo;
    # generate private variable for object
    has $!bar;

    And then because Perl 6 has changed to some extent, instead of doing $.bar isa Int, you’d do the following:

    1
    has Int $.foo;

    Also, as far as we could discover in our short meeting, instead of before, after, and around, in Perl 6 you’d use wrap. I *think* it would work like this, but I’m not sure:

    1
    2
    3
    4
    5
    class Foo extends Bar {
       $.method_from_bar.wrap({
          # codez
       });
    };

    After that we had a heated discussion about whether using wrap was monkey patching/violating the Liskov substitution rule. I stand with the majority that it is not.

    We also did some initial planning for a monthly hackathon, which is exciting. The idea is to have the hackathon two weeks after the meeting, so we can kinda plan ahead. We’ll see how well that goes down.

    If you live in the DFW area, you should get in touch and visit!

  • 1 Comment
  • Filed under: Uncategorized
  • The project I am working on right now is rewriting a large, mostly CRUD application. The current app (second generation) is all VB6 and Stored Procedures. We are making the app entirely web based with DBIx::Class for the brunt of the backend and ExtJS for the UI. There are a few other technologies involved, but they should remain fairly light and unobtrusive.

    As we’ve designed our code I’ve made an effort to only look at the inputs and outputs of the original code, to avoid using any existing design mistakes that have already been made. Generally this methodology works well. But sometimes the very format of the input/output leads me astray. Here’s an example that I encountered today.

    Our customer typically uses composite primary keys to allow for public facing id’s. That makes sense. Typically serial numbers follow actual reason and composite primary keys work for that use case. In some places these keys are also the natural ordering for a set of items. For example, the company will have a list of operations that were performed to fix a part. Those operations are listed in order (for obvious reasons) and that order must be maintained. The id makes sense initially. Yet sometimes people need to change the order of some of these things. The most specific part of the composite pk always starts at one and increments by one. So when the user reorders the items in the list we ddo something like this (from memory):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    method set_id ($new_id) {
       my $old_id = $self->id;
       my $siblings_to_increment = $self->siblings->search({
          id => {
              '<' => $old_id,
              '>=' => $new_id,
          },
       });

       my $siblings_to_decrement = $self->siblings->search({
          id => {
              '>' => $old_id,
              '<=' => $new_id,
          },
       });

       $self->result_source->schema->txn_do(sub {
          $self->update({ id => 0 });
          $siblings_to_increment->update({ id => \'id + 1' });
          $siblings_to_decrement->update({ id => \'id - 1' });
          $self->update({ id => $new_id });  
       });
    }

    Works great!

    But today I was considering what this would be like if I were to remove the composite pk’s from the system. How would I order the items? I would no longer change the id because they would be completely unique and reordering would be a big hassle. Solution? Real numbers! If you have 1 and 2 and you want 3 to be between them, you set it to 2.5! or if you want to displace 2 with 5 you set 2 to 1.5 (or 2.5) and just set 5 to 2. Of course you’d need some code to find the midpoint ((x+y)/2). But that’s no big deal.

    Now, I’d like to think that I would have come up with that (simpler) solution originally if I hadn’t already assumed the database format that we have. Although the first form was fun to come up with it is inferior to this. Id’s should really be forever, and ordering shouldn’t change the id of a thing. Anyway, keep that in mind when you do your rewriting and reverse engineering. Think of the data as it would be if you’d made it originally, and simpler solutions may come to you out of the blue.

  • 3 Comments
  • Filed under: Uncategorized
  • Mediums and Messages

    When you want to get help on the internet, it’s not just what you say and how you say it; it’s also where you say it. I use three different communication mediums on a day-to-day basis to get help with the various toolkits I use and only a couple of them overlap in medium. There are inherent benefits and drawbacks to each medium, but generally you don’t have a choice in which medium to use for a given project.

    At $work we use the ExtJS framework for UI stuff. We use their paid forums. There are a group of ext users who use IRC but I never found the channel to be any help. So with Ext you use a forum if you want help. Forums are nice because there can be built in code formatting, all the archives are right there, you only have to see the messages when you really need them, and you an have built in categorization.

    I used to use CGI::Application. The best way to get in touch with those guys is to use a mailing list. They have an IRC channel, like the ext guys, but in a week there are about as many conversations in as many days. So mailing lists! Mailing lists are kinda intimidating to get into. Partially because if you stop using a toolkit you keep getting the mail. Or when you don’t have a problem you keep getting the mail. But ultimately this is a really good long term solution, because you tend to have people who use the toolkit who, dun dun dun, check their email! A drawback of this medium is that there is no built in archival (although typically it is archived) and any source code formatting is done in plain text.

    Both DBIx::Class and Catalyst primarily use IRC for support. They have mailing lists, but you can get information and simple answers much faster on IRC. The beauty of IRC is that it is realtime. So you have people having regular conversations as well as getting answers to questions. One of the major issues with IRC, in my mind, is that code must be shown separately, in a pastebin website. There also is no built in archival, or even persistence. Nonetheless, this is very common in largish open source projects.

    And there you have it! fREW’s useless list of mediums that go with a handful of projects!

  • 0 Comments
  • Filed under: Uncategorized
  • Initial Catalyst Impressions

    I’ve been using Catalyst at home for nearly six weeks now and I guess two weeks at work. I feel that now is a good time for me to list some of my impressions.

    The angle that I am coming from is mostly CGI::Application, which means very bare bones.

    The first thing that I got for free with Catalyst was configuration file support. Less than a week after switching to Catalyst our customer asked me if we could change the database connection easily. Previously I had that set in an environment variable in the Apache config. Although that’s still something my customer could easily do, it’s certainly not as easy as other forms of configuration.

    Chained Actions are an interesting way to allow code reuse in Catalyst controllers. Basically they allows one to automatically call a number of methods in a given order automatically based on the path. One would typically set various per-request values (stash) in the chained methods. The following is an example.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    method load_req($c, $id): Chained('/') PathPart('groups') CaptureArgs(1) {
       my $user = $c->user->obj;
       $c->stash->{group} = $user->created_groups->find($id);
    }

    method view($c): Chained('load_req') PathPart('') {
       $c->stash->{selected} = { map { $_->id => 1 } $c->stash->{group}->users };
       $c->stash->{template} = 'groups/view.tt';
    }

    method add($c) :Chained('load_req') PathPart('add') {
       my $group = $c->stash->{group};
       my $user = $c->user->obj;

       # find people who are already friends
       my $friends_to_add = $user->friends->search({
             id => { -in => $c->req->params->{friends} }
          });

       while (my $friend = $friends_to_add->next) {
          $group->add_to_users($friend);
       }

       $c->response->redirect(
          $c->uri_for( $c->controller('Group')->action_for('view'), [$group->id] )
       );
       return;
    }

    So basically how that works is that /groups/1 will call load_req and then view whereas /groups/1/add will call load_req and then add. You can see that because load_req starts the chain (‘/’), names itself groups (PathPart), and then says it takes a single argument (CaptureArg). But it cannot be called directly, because it’s not an endpoint. Any argument with CaptureArgs is not an endpoint. This isn’t a tutorial, so I won’t try to explain it in depth. Either way, it can significantly increase code reuse.

    Flexibility is another great thing about Catalyst. Catalyst::Action::REST allows one to easily use Catalyst in a RESTful manner. It automatically handles serialization, deserialization, and dispatching. Here’s the cool thing; when there is an error in my app at work it needs to return a 500 as well as valid JSON. A REST controller will return an html error if there are errors. I don’t want to override the end method, because it’s what does the deserialization. Moose to the rescue! Basically what I do is define a before method that will put data in the stash if there are errors. Then the real end method runs and outputs the errors as JSON. Again, this isn’t a Moose tutorial, so I won’t show all the details. Maybe another post.

    Of course because of the increase complexity Catalyst is harder to learn, but I haven’t actually found it that much harder than CGIApp. It’s nice and regular, so once you know where to look in the doc for what you need it’s not that bad. Although I guess that’s the same as most large projects :-)

  • 2 Comments
  • Filed under: Uncategorized