A Foolish Manifesto

fREWdiculous!

Turns out there really are Computer Gremlins!

Ok, this is just too crazy to not record and relate. By now anyone who has read much of my blog or interacted with me should know that I use a significant amount of javascript on my current project at work. Because I like to keep everything nicely organized, 95% of the time each class has it’s own file. That means I have to tell the server every time I add a new class. No big deal really.

So yesterday I created a new form, and I added it to the list. When I refreshed the page the form failed to load. Well, that could have easily been an error in the syntax or even runtime logic of the form, so I start looking for firebug errors and whatnot and don’t see any. So I look at the debug output of Catalyst::View::JavaScript::Minifier::XS to make sure that it tried to include that file. It didn’t! Ok so clearly I didn’t save the file with the list of JS files. So I ensure that I’ve saved it. Still no luck. So I change another part of the list, a file that is loading, to see if that gets taken out of the list. Maybe I misspelled the filename you know? Nope. List remains the same. Ok, so then this must not be the canonical list. So I change a fundamental part of the list, to see if everything still works after I change that. Nope, now nothing works, showing that this list clearly isn’t nothing.

Bizarre. So I go home, assuming that I was just tired. Today at work, after working on a bunch of other stuff, I get back to it. So first I output the list itself, to make sure that it’s what I think it is. It is. Then, I open up the code behind Catalyst::View::JavaScript::Minifier::XS. I added some debug stuff where it loads the files and look at the output. Nothing prints out. That’s weird… So I change it from a warn to a $c->log etc. Still no output. So I’m editing the wrong file, obviously. I go to rename the system version of this file so I know it’s using my local copy (I have changes that haven’t been accepted by upstream yet.) Oh wait…it’s already renamed from yesterday…

So that’s weird. Ok, so I put some debug statements right next to where it already has some debug statements… Lo and behold they output! Ok so clearly I am missing something. I put debug statements before the block where I am already outputing debug statements from: no luck. I put them after. No luck. I change the code so that all the filenames get “frew” added to the end to see if CVJMX will throw an error or even change the output messages. STILL NO CHANGES.

I should point out that I have checked that I am using my local server and editing local files numerous times by the way.

Ok, so I am clearly insane at this point, as that’s more likely than file changes being scoped to a 3 line block. On a whim I decide to restart my computer. Start the Catalyst Dev server with the same command (from history) as before, without file changes. Everything worked.

All I have to say is: jfkasl;fkdasfkojqwklmdcszkljcvsxlkv m,w;ejriopjewiojc4weojejoifevjoirjivoi

  • 4 Comments
  • Filed under: Uncategorized
  • Why should I use an ORM?

    At work I tend to play an…Evangelical role? I tend to experiment with various technologies, get sold on them, and then sell them to coworkers. Examples: Apache, DBIx::Class, CGIApp, and lately Catalyst. So I typically find various ways that the new tool helps make my job easier and tell people about that. After they believe me, I then educate them about various nuances and whatnot of the tool. Eventually this will happen with git, when it doesn’t suck so much with Windows.

    So recently one of my coworkers asked me why he should use an ORM. I had thought I’d mostly fought that battle, but he wasn’t sold (he is now by far :-) ). Anyway, here is my answer, open to the world.

    ORM’s let you forget SQL

    In general this isn’t a huge benefit. SQL is pretty simple and remembering it’s syntax isn’t so bad. But when you want to do something in like paging in SQL Server is when an ORM really starts to shine. In general the ORM makes tasks that you want to do with SQL all the time nice and simple. For example, since we use Ext at work for most grids, users expect to be able to sort by all columns, have pagination, etc. That’s entirely abstracted away. I rarely think about those pedestrian things now :-)

    ORM’s allow you to predefine the relationships between your tables

    This is where a good ORM really shines. Instead of trying to remember seemingly transient relationships, like how the Shop table joins with the Orders table, we can document that by writing code using our ORM. After that the relationship is there forever. It’s an entirely new level of code reuse, if you are used to just vanilla SQL, even if you are reusing it with functions.

    ORM’s give you all the features of OOP

    This is actually a lot more subtle in my mind. When I first started using a ORM for real (DBIx::Class) I kept looking for DBIC ways to do various things. Typically the answer was: “override insert” or “override update.” As a noob this can be pretty intimidating, but it really gives great amounts of flexibility. At some point I’ll do a post on OOP revelations I’ve had (interestingly, mostly I get those from hacking on the code of my ORM of choice :-) ,) but for now I’ll just leave it at that.

    What are the reasons that you use an ORM?

    update: as Stevan notes, I really shouldn’t say all in the final bullet point above. It’s more subtle than that. When I say OOP I don’t actually mean the classes that the ORM represents inherit from each other. I just meant that if I want to do some extra stuff for one class when I store/retrieve it I can localize those changes.

  • 4 Comments
  • Filed under: Uncategorized
  • Brief Addendum: Send Email

    Ok, so for some reason I left out sending email from last nights’ post. Here it is: sometimes people forget about RT, or they have so many RT’s that they don’t know which ones are fixed and broken. Well, a small nudge via email can convince them to fix a longstanding bug. Of course, if it’s reasonable sending a patch wouldn’t hurt either…

  • 0 Comments
  • Filed under: Uncategorized
  • How to Help without being a Rockstar

    I think a lot of people who use perl have the idea that to help the perl ecosystem be they must be rockstars who churn out exorbitant amounts of code that is well tested and well factored. That is just not true!

    The easiest thing one can do to help out in the perl ecosystem is to create tickets for any issues you have with modules on RT. It’s not really that much of a hassle and it can help authors out a lot. Make sure that you include enough information for the authors to at least understand what went wrong. I won’t explain all that as my audience is comprised of programmers.

    in that same vein, sometimes people forget about RT, or they have so many RT’s that they don’t know which ones are fixed and broken. Well, a small nudge via email can convince them to fix a longstanding bug. Of course, if it’s reasonable sending a patch wouldn’t hurt either…

    Another thing which I’ve mentioned before is to use CPAN ratings. Again, this is super easy, but if the module works for you and you have no complaints, 5 stars can really tell other users a lot!

    And then of course there is communication on IRC. Often on IRC, after a user asks for clarification, developers will ask for a doc patch. Although this is easy for the user to add (depending on the subject of course) it will help future users significantly.

    How many RT’s have you submitted this week? CPANRatings? Doc Patches?

  • 3 Comments
  • Filed under: Uncategorized
  • reCAPTCHA

    Normally I opt to eschew metablog post (how meta is that?!) but I figured this deserves a brief explanation.

    I have been getting more and more spam lately. Fortunately Akismet usually keeps humans from seeing it, but Akismet has also kept back plenty of spam too. So I decided to go with the more powerful reCAPTCHA for comments from now on. I know it’s a hassle, but it could be worse. There are lots of bad CAPTCHA plugins out there and in general I like the reCAPTCHA concept. Anyway, sorry!

  • 4 Comments
  • Filed under: Uncategorized
  • 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