Should you have NULL's in your database?

So recently I made a post regarding NULL’s and “ with respect to numeric fields in a database. I asked questions on a couple different mailing lists for help and one of the interesting responses I got was that You Shouldn’t Have NULL’s In Your Database Unless Required. Now, I totally understand that for strings, which is all the noted article actually discusses. But my issue wasn’t with a string, it was with a number.

Posted Sun, Jul 12, 2009

Form Validation Sucks.

This is just a rant. I am so sick of validating forms. I do all that I can to make it easy and whatnot, but it still comes back to spite me! Here are two examples of things that are dumb: Checkboxes So html checkboxes are SO DUMB. If they are checked, the value is set to ‘on.’ That’s annoying alone, but if the checkbox is not set it doesn’t even get submitted!

Posted Thu, Jul 9, 2009

Model Based Security

So this is probably old hat to those people who are already big on architecture or know a lot about design patterns, but I thought it was a pretty clever implementation of data security. Anyway, first I’ll start off with how I actually did it, and then maybe talk about it in the abstract. So here’s the idea, I have a user, and that user should only be able to view a certain set of messages.

Posted Wed, Jul 8, 2009

Don't be a jerk

So there’s a certain meme that’s been pretty popular in the perl community lately. I won’t mention it because I think it’s really been discussed too much. The problem I have is that really hurtful things have been said on both sides of the discussion and it’s really too bad. I posted a while back about how glad I was that we aren’t the Ruby community; banning each other from conferences and whatnot.

Posted Tue, Jul 7, 2009

Chapter 7: Open Source

Some of you probably know that I have some opinions, thoughts, and ideas. I actually started this blog because I wanted to write my own (can you guess what?) Manifesto. I chose to write it as a blog because I tend to change my mind. Ask some of my friends and family. They have all observed that I was going to be a math teacher, a psychologist, a biological engineer, a doctor, and a writer.

Posted Sat, Jul 4, 2009

Album of the Week: Ladyhawke

Sorry I’ve neglected the Album of the Week. It’s really hard to write about music. I think I am going to make my requirements for AOTW postage less strict. So with that in mind, this weeks Album of the Week is the eponymous Ladyhawke. It’s a very 80’s sounding album by the interesting artist Ladyhawke. According to Wikipedia Ladyhawke has a weird seagull disease, Asbergers syndrome, and is allergic to medicine?

Posted Thu, Jul 2, 2009

Pair Programming with a Customer. EXTREME.

The week before YAPC was terrible. First my AC went out. That’s a drag in Texas. Because the AC was out, my apartment got really hot, I couldn’t sleep, and then the mantle fell off the wall. That was crazy. Then I found out that I purchased a plane ticket to Raleigh, NC for a family reunion for the same days as YAPC::NA. That cost me an excellent $500. And then (I think Thursday?) I did something that was pretty crazy.

Posted Tue, Jun 30, 2009

Finding the Optimum Meeting Location

So I just got back from a family reunion. My family is all about Modern::Reunion, or maybe Enlightened Reunion, or maybe Reunion foo + i. So with this reunion at the end a survey (done with Google Docs) was sent out. My mom asked me if I could somehow find the weighted middle of where everyone (42~ people) lives. So I was all: CENTROID. First off, Centroid on Wikipedia. What we want is the first equation, which is surprisingly simple: average!

Posted Tue, Jun 30, 2009

YAPC Day 2

This is day 2 (my final day :-( ) of YAPC. I tried my best to keep reasonable notes but near the end of the day my brain started to slow down. Hope you dig it nonetheless! The Future of DBIx::Class FYI: mst doesn’t use a mic, he yells. Instead of using MI, the future will use Moose and Roles. Good things DBIC already did: Everything objects (almost no class methods) Schema object multiple connections storage and cursors are objects hides away backend specifics ResultSource object table/view metadata not tied to the class so multiple classes associated with the same table relationships near side, far side, join condition no single columns assumptions for keys result class (inflate_result) minimal protocol ResultSet (my favorite) virtual view pure functional chainable updatable cacheable RestrictWithObject is a really cool use of this stuff Extensible were an accident ‘aha’ moment needed Result Class vs ResultSource list context vs scalar context search() args vs find args() aha moments indicate conceptual inconsistency essential vs implementation complexity Bad things: find() deflates, search() doesn’t connection attached to schema instance details result in underlying design mistakes persistent vs.

Posted Tue, Jun 23, 2009

YAPC Day 1

Today was the first official day of YAPC. A lot happened! I’ll just document what was interesting :-) First there was an intro. The Pittsburgh guys did a lot of work to get it all to work. Enjoy. The Perl Foundation has had a big year. Mostly with updating p5 and working on p6. The Parrot Foundation (ParF) got created. Big deal. Larry’s talk He barked at us! And then played many other sound effects.

Posted Tue, Jun 23, 2009

YAPC::NA - Day -1: Moose

Today was the first day (for me) of YAPC::NA. It was pretty cool! A coworker and I convinced our work to pay for us to go to YAPC and go to the Moose Masterclass. The class was very good. I thought that the slides were very complete and that the exercises were great for a professional conference. Basically he would present a major section of Moose (there were 4 or 5 I think) and then he would tell us to get going on the Classes for that given library.

Posted Mon, Jun 22, 2009

DBIx::Class vs Class::DBI vs Rose::DB::Object vs Fey::ORM

Recently (6 monthsish ago) I decided on an ORM to use at $work. It was pretty hard to make a decision because I’d never really used an ORM for a significant amount of time. Now that I am pretty confident with my chosen ORM I feel like I can make a more informed comparison. I’m going to skip over the basics of declaring classes themselves. Often when researching ORM’s this is the main thing that people look at.

Posted Fri, Jun 19, 2009

Why you should validate in your controllers and not your models

Okay, I got some responses based on my question yesterday about why validation shouldn’t be in the model of an MVC-based app. This is what I got out of the responses: Models don’t know about the current user (or other higher level information) This means that if you have some kind of time based input the timezone modifications need to happen in the controller. Or the even better example is that sometimes a user can change more of a model than another user based on the user’s permissions or roles.

Posted Thu, Jun 18, 2009

When should I validate in controllers and not in models?

I’ve been told numerous times by people that I believe are smarter than me that I should do validation in my controllers and not my models. mst said that some validation, like low level primary key type stuff, can be in models, because it has to be. But if I recall correctly almost everyone was against validating things like email addresses in my models. I just read this article and a lot of what alias says seems to make good sense to me.

Posted Wed, Jun 17, 2009

Dallas.p6m: June

This month’s Dallas.p6m was bigger than before! We had my coworkers Geoff, Neil, and Wes, myself, Graham Barr, Jason Switzer (s1n,) Patrick Michaud, and John Dlugosz. We got a domain hooked up (dallas.p6m.org, which doesn’t point at anything yet,) discussed interesting stories about rakudo optimization (and often lack thereof,) and sometimes delved into perl5 stuff. s1n decided to mention that we need to start doing our feature expositions, which is where someone picks a feature in perl 6, does some research, does a talk on it, and then we write some code which is based on it.

Posted Tue, Jun 16, 2009

Compare and Contrast CGIApp and Catalyst

You may remember my post from before asking about the differences between these two frameworks. I only got a couple of responses, but they certainly helped me to see what is up. Basically it boils down to this (as pointed out by mst): CGI::Application is a microframework, and Catalyst is an extremely configurable MVC stack. Before you correct me, Catalyst doesn’t actually provide the Model or View code; it lets you pick whatever you want to pull that off.

Posted Fri, Jun 12, 2009

Contributing to Open Source

I’ve used Open Source for a little over ten years now. I’ve been sufficiently indoctrinated that Open Source (Free Software) is both morally and technically the right choice. That’s not what this post is about. If you disagree with those premises, that’s fine. The idea here is that I use all kinds of Free Software all the time. I use Vim for a text editor. I use zsh as a shell.

Posted Thu, Jun 11, 2009

Avatar!!!

I recently purchased an Avatar to be created by Scott Meyer of Basic Instructions. Today he sent me the completed avatar. Here it is: Pretty sweet, huh? Anyway, I figured this would be cool, because I get to look cool and support an excellent webcomic/artist. Get your own here! Oh yeah, and maybe you want to see the original. That was done by my roommate at the time.

Posted Wed, Jun 10, 2009

CPAN Mashup?

One of the common issues I hear about CPAN is that it’s so sprawling that people do not know which modules to use and which not to use. Hopefully part of that issue will be solved by the Enlightened Perl Core, but that will only go so far. Recently there were a couple posts regarding this issue. (Note: They are in reference to a post I made and they are from the same guy.) I even recently had a discussion regarding this with my boss recently because we needed some barcode generation code.

Posted Tue, Jun 9, 2009

Vim Feature of the Day: gv

Have you ever highlighted something in vim, yanked it, and then realized you wanted to yank it to a different buffer, often + or *? Well, try the command gv. It will highlight whatever you had previously selected. I probably use it at least once a day. Enjoy! If you’d like to learn more, I can recommend two excellent books. I first learned how to use vi from Learning the vi and Vim Editors.

Posted Mon, Jun 8, 2009

WorldOfGoo

I just completed World of Goo (or buy direct, here). Very fun game! I like video games, but I tend to not play them very much because I do all kinds of other things (lots of programming if you can’t tell :-) ) but recently I’ve found that they help me clear my mind when I am trying to figure stuff out. Like, I’ll be coding and I will usually get stuck on a design issue.

Posted Sat, Jun 6, 2009

Future Post: Compare and Contrast CGIApp and Catalyst

So I’d like to do a post on CGIApp and Catalyst. People on IRC keep telling me that using CGIApp is wrong (mostly because they’ve never used it) and that I should switch to Catalyst. Catalyst may be great, but I haven’t seen any solid posts about how Catalyst is great. So help me out. Ignoring the fact that Catalyst is what everyone uses (so there are lots of plugins for it) what makes it so good?

Posted Fri, Jun 5, 2009

Windows Agony: Con

At $work I manage the subversion repositories for all of the software that we develop. It’s certainly not something that I’m great at, but I’ve used it longer than most so I am the most qualified to deal with it. Furthermore, at work we use this tool (Freescale?) which, when it creates a project, creates a Boot directory and a Con directory. Ok, so I had helped our head honcho EE create a repository to store his project data and versions.

Posted Wed, Jun 3, 2009

Web Comic Downloaders

Since the beginning of my serious webcomic journey with xkcd, I think that was four years ago, I’ve been writing little scripts to help me get started. The first type of script is to grab integer-based, monotonically increasing files. Very easy. Done in Ruby. #!/usr/bin/ruby -w Fromat = "http://foobar.com/comics/%08d.gif" 1.upto(986) do |i| `wget #{sprintf(Fromat, i)}` sleep 1 end The next harder are the ones that are based on the date of publication.

Posted Tue, Jun 2, 2009

Script to Rename MP3's

I recently got a new car stereo due to the other one being stolen. I am almost entirely happy with the model that I ended up purchasing, but one thing that it does, which is really obnoxious, is that it doesn’t sort the files correctly unless the track number is early on in the file name. Even if all tracks are “FooBarBaz 01 - name.mp3” it seems to ignore the number unless it’s the very beginning of the file name.

Posted Sun, May 31, 2009

DBIC'd

This is a blogish version of a message I posted to the DBIC Mailing list recently. First off, this is my table structure: User has many Roles (Role belongs to User) Role has many Permissions (Permission belongs to Role) Permissions has many Screens (Screens has many Permissions) Screens belongs to Section (Section has many Screens) So I thought I could do this: my @sections = $user->roles ->related_resultset('permissions') ->related_resultset('screens') ->related_resultset('section') ->all; But related_resultset doesn’t work with many_to_many because it’s not a “real” relation (I’d like to hear about why that is at some point.) The following is close to what I wanted my @sections = $user->roles ->related_resultset('role_permissions') ->related_resultset('permission') ->related_resultset('permission_screens') ->related_resultset('screen') ->related_resultset('section') ->all; But it turns out it returns a section per role, which often means duplicates.

Posted Fri, May 22, 2009

Don't Repeat Yourself: JSON

With DBIx::Class we typically have a TO_JSON method which returns a hashref of the data you want in your json. Here’s an example: sub TO_JSON { my $self = shift; return { id => $self->id, name => $self->name, comments => $self->comments, email => $self->email, job => $self->job, ok => $self->ok, i_cant => $self->i_cant, think_of => $self->think_ok, anymore => $self->anymore, }; } Here’s the shorter version mst inspired me to write: sub TO_JSON { my $self = shift; return { map { $_ => self->$_ } qw{ id name comments email job ok i_cant think_of anymore }, }; } Anyway, not very complex, but still awesome.

Posted Tue, May 19, 2009

Perl 5 to Perl 6 Rewrite

My coworker Wes asked me if there could be a nice refactor for the following function which checks CAS Numbers to ensure their validity. After struggling for 30 minutes I gave up trying to make it a little bit nicer with reduce. sub cas_old { my $cas = shift; if ($cas =~ /\d{1,8}-\d\d-\d/) { my @ary = grep { $_ ne '-' } split(//, $cas); my $check = pop @ary; my $count = @ary; my $sum; for (@ary){ $sum += $_ * $count--; } return $sum % 10 == $check; } return; } Let’s take a look at this and figure it out.

Posted Fri, May 15, 2009

Dallas.p6m: May 2009

We had the second Dallas.p6m on May 12, 2009. Along with me there were two of my coworkers, s1n, Graham Barr, and Patrick Michaud. We discussed a lot of things. One of which was the difference between subs and methods in Perl6. And the fact that you can’t imply self. This should explain it: class A { sub foo { say 'foo'; } method bar($o:) { # much to s1n's chagrin, you can't # have baz() imply self.baz.

Posted Fri, May 15, 2009

What I want from the Perl 5 support policy

This is in response to chromatic’s post Writing Perl 5’s Support Policy I want to be able to use the support policy as a reason to convince customers with lots of Perl installs that they need to update. A big part of this means an easy upgrade. Probably most of the people using Perl 5 are in Unix. That makes it easier for you folks. On Windows installing Perl is no simple task, either ActivePerl or Strawberry Perl.

Posted Thu, May 14, 2009

Profilers or more specifically NYTProf

At work one of our customers is having us revamp one of the major sections of the site. We are moving in the “Web Application” direction; that is, very little HTML, and almost all Javascript. The section of the site that my coworker was working on recently does a lot of calculation. On the old HTML page a customer would log in, ask for a certain report, and I guess go get a cup of coffee.

Posted Tue, May 12, 2009

Concert of the Month: Astronautalis

Saturday night my roommate and another friend went to see Astronautalis. He was actually sandwiched between Valina and The Paper Chase. Valina was a generic rock band that I can’t imagine ever going to see just for them. They just didn’t seem to bring anything special to the table. The Paper Chase were Dissonant Rock and most of their songs sounded the same. We left after their fourth song I think.

Posted Tue, May 12, 2009

Friday Refactor

It’s Friday, so a long post is not in order. With that in mind, a simple refactor for your pattern matching skulls and skills: before: my @files = File::Find::Rule->file()->name('*.t') ->maxdepth( 1 )->in( File::Spec->catdir( $self->get_directory, 't' ) ); my @total_results; foreach my $file (@files) { push @total_results, "<span class="file">$file</span>"; push @total_results, @{ $self->test( $file ) }; } return join "\n", @total_results; Do you see what I see? We’re iterating over a list and generating a new list… And then we are just doing a join on that.

Posted Sat, May 9, 2009

Album of the Week: Space Revolver

I have had quite the love affair with prog-rock. One of the bands that led to this affair was The Flower Kings. I think the third album of theirs that I got was Space Revolver. Space Revolver is very much prog and very much Flower Kings. For instance, the first song, I Am The Sun (part one) has lots of noise and even a weird (but awesome) sub-song that most bands certainly wouldn’t do.

Posted Fri, May 8, 2009

Making MSDOS a little bit nicer

I work at a Microsoft Company more or less. We use SQL Server, IIS (moving to Apache…), and various flavors of Windows for all of our machines. I haven’t had the cojones to install Ubunutu on my desktop yet, so I am stuck with cygwin and friends. But the perl that runs my server is not in cygwin. That means that if I want to do valid testing I have to do it with the regular perl.

Posted Fri, May 8, 2009

Perl6 Excitement

“I estimate that Rakudo starts up nearly 40% faster now than it did when I started on Sunday night. We can get it faster yet.” –chromatic

Posted Fri, May 8, 2009

Testing with Perl: awesome

Sometimes when I get close to the end of the day and it isn’t feasible for me to start on something new I expand on my current project’s test suite. Recently I worked on one of the (seemingly) more complex ones. Basically it tests one of our autocompleters to ensure that it will search for the name and also the public facing id of a certain field. The id part was easy.

Posted Thu, May 7, 2009

Future Perl

This is mostly stuff I’ve gathered from this talk and updated slightly. First off, have you ever tried to teach a programmer perl? I have. Note this: sub foo { my ($self, $bar,$baz) = @_; #... } # or often sub station { my $self = shift; #... } The following is more palatable to most coders (also I like it better:) use Method::Signatures::Simple; method foo($bar, $baz) { #... } method station { #...

Posted Thu, May 7, 2009

Flight of the Conchords live

I’ve decided that seeing a concert warrants a blog post, and that a concert blog post can fill in for an Album of the Week post. If I pay the money to see a concert (typically more than the cost of a CD) I probably like the band that much :-) With that in mind I present to you my most recent concert: The Flight of the Conchords. You’ve probably already heard of Flight of the Conchords.

Posted Thu, May 7, 2009

Glad to be part of the Perl Community

I’ve mentioned this in at least one previous post before, but it bears repeating. First off, here’s some context for the varied information I am about to throw out at you, dear reader. I keep in touch with both the Ruby and Rails worlds because I think they have some really good ideas. Recently there was a conference session about CouchDB. I read the slides and I was impressed. CouchDB is cool stuff!

Posted Wed, May 6, 2009

WebCritic: standalone version

Ok, you guys asked for it. I have updated WebCritic to be a lot leaner and meaner. Get the new version at the same great place. It now runs entirely in it’s own lightweight server. No apache or mod_perl needed. It now uses CGI::Application::Server. It no longer uses CGI::Application::Dispatch, as my end goal no longer requires it. CAS fills the gap that CAD did for me. I also removed all of the lines that needed perl 5.10 because I wasn’t actually using any perl 5.10 features.

Posted Tue, May 5, 2009

Moose makes Perl OO Sexy!

We should have all heard of Moose by now as a great way to do OO with Perl. While I was working on WebCritic I decided that it would be a good idea to hook my OO stuff up Moose style. I figure that even if I were to just write code and then disappear I might as well write 2009 code instead of 1999 code so that if it ever gets copied it will bless the copier instead of curse them.

Posted Fri, May 1, 2009

Testing: Way Cool!

When I was writing WebCritic I decided that the code was small and simple enough that it would be a great candidate for me to figure out how to set up automated testing for the whole stack (except for the javascript.) This is something that I’ve wanted to do at work for a long time but I feel bad spending time figuring out stuff like this on the customer’s dollar. I already had Perl Testing: A Developer’s Notebook and I figured I’d use it to get a start.

Posted Thu, Apr 30, 2009

PerlCritic for Web Developers

I like to continually move towards perfection in my code. perlcritic is a tool based on the book Perl Best Practices by Damian Conway. It’s basically lint for perl. perlcritic is fine as it is if you spend all day on the console, but I usually spend my whole day in Firefox and vim. The only use for my console is checking in source and using irssi. There are a few other things I use the console for, but the point remains, I spend more time in Firefox than I do in the shell.

Posted Wed, Apr 29, 2009

Hey guys! You should blog too!

Check it! Ok that article is really long. Here’s the breakdown. Basically Matthew S Trout, the main guy who makes DBIx::Class, made a similar observation as other people. More specifically, Perl people don’t blog enough. With that in mind Mr. Trout gives some compelling reasons to start! So read the article. Also: lots of things are coming out lately! Ubuntu 9.04 just got pushed to my laptop, and my phone is gonna get updated from 1.1 to 1.5 (read: on screen keyboard!) in less than two weeks!

Posted Fri, Apr 24, 2009

Perl::Tidy: annoying facts

So I was trying to use perltidy programmatically, that means using Perl::Tidy. Basically I wanted to use an existing .perltidyrc along with the backup option. That is, instead of making a new file with .tdy at the end, replace the original and back it up to .bak. So after reading the docs I figured that this should work: use Perl::Tidy (); use File::Spec; my $file = File::Spec->catfile( $dir, $filename ); Perl::Tidy::perltidy( source => $file, argv => '-b', perltidyrc => $perltidyrc, ); Unfortunately that just doesn’t work.

Posted Fri, Apr 24, 2009

Vim Tip of the Day

Every now and then I want to run a given vim command on a bunch of lines. In the past I would have either executed the command and then pressed j. (Hi J-Dot!) to go down and repeat the command. Or if the command were more complex I would have used a macro and done it over and over with @@. Well, for simple stuff on a range there is an easier way!

Posted Thu, Apr 23, 2009

Why CPAN is Awesome

Have you ever written a server? It’s kinda fun! Yes, I’m a nerd. Anyway, I learned the easy way and the hard way to make a server in Perl yesterday. Here’s the easy way: #!/usr/bin/perl use strict; use warnings; use feature ':5.10'; use Socket; use Carp; use constant PORT => 7890; use lib '../lib'; use WebCritic::Critic; my $dir = shift; my $port = shift || PORT; my $proto = getprotobyname 'tcp'; # create a socket, make it reusable socket SERVER, PF_INET, SOCK_STREAM, $proto or croak "socket: $!"; setsockopt SERVER, SOL_SOCKET, SO_REUSEADDR, 1 or croak "setsock: $!"; # grab a port on this machine my $paddr = sockaddr_in( $port, INADDR_ANY ); # bind to a port, then listen bind SERVER, $paddr or croak "bind: $!"; listen SERVER, SOMAXCONN or croak "listen: $!"; say "SERVER started on port $port "; my $client_addr; my $critic = WebCritic::Critic->new({ directory => $dir }); while ( $client_addr = accept CLIENT, SERVER ) { # find out who connected my ( $client_port, $client_ip ) = sockaddr_in($client_addr); my $client_ipnum = inet_ntoa($client_ip); my $client_host = gethostbyaddr $client_ip, AF_INET; # print who has connected say "got a connection from: $client_host", "[$client_ipnum] "; # send them a message, close connection say CLIENT $critic->criticisms; close CLIENT or croak "couldn't close connection!

Posted Thu, Apr 23, 2009

Album of the Week: Anywhere I Lay My Head

This week’s Album of the Week is Anywhere I Lay My Head by Scarlett Johansson. The album is comprised of Tom Waits covers done by Johansson. According to my friend Neil and also Internet, Dave Sitek, also made quite the impression on the album as a whole. The main impression one gets from the album is it’s muddled sound. It’s as if Johansson is singing from the bottom of a lake or something.

Posted Wed, Apr 22, 2009

More Tools Monday

So I am working on a new way to use perlcritic, and one of the things I’d like perlcritic to check for is a correctly formatted file. Unfortunately the integration between perlcritic and perltidy goes something like this: Tidy the file with perltidy Give vague error if tidy file != original file That’s fine until you discover that = signs get aligned and apparently you cannot turn that feature off. That means that my code gets marked sketch if I don’t align my = signs.

Posted Tue, Apr 21, 2009