Wednesday, December 28, 2011

mac os x xattr and "protected" files (post download)

Mac OS X (10.6 maybe older or new) sets 'quarantine' bit on files and directories downloaded and unarchived (or just downloaded).

Its a good idea to warn users what they are opening but this is a pain if the an archive is opened but then you want to move it somewhere else that isn't using typical OS X apps that understand and can clear this perm. (like unix dev location under webserver).

I've found this xattr command to work to clear out that problem:
xattr -d -r directory

It will verbose blurb out stuff but at least it gets rid of it and allows reading of those files by various unix programs (like apache).


Friday, October 28, 2011

jQuery - "getting" chains

I've been using jQuery for quite a while now. I really like its interface, often it feels very Perlish to me.

But in the past I've struggle when trying to process or access parts of a single element returned by a selector. Most of the time, I really want to grab it with an array index, e.g.
(just some rough example).

But that always felt wrong, against the jQuery way, like i was an outsider. Esp when its so natural do things like:
$('a.special-sauce').click( function() { // do something } );

I've tried to use the first() method to get a single element but that returns an array too. But I finally got how to use it today...

We are using jQuery Tools for overlays and some other actions. I wanted to retrieve the href attribute for the trigger object (the one that was clicked to open the overlay (aka lightbox). I tried the wrong feeling:
and had the moment of clarity that said "that really means:
And now i get it (for now) :)

Since I want some part of the element like an attribute or value I can use the first method with either attr or val methods (or whatever part of the element I really want).


Wednesday, October 26, 2011

jQuery placeholder plugin

We have moved to using the jQuery plugin placeholder-enhanced for adding placeholders to browsers that don't support them (i'm looking at you IE9).

It seems to work better than the other plugins and libraries out there (we tried placify which had some trouble when pages resized or if forms were hidden in lightboxes).

It looks like placify creates a div with text (and class) positioned above the input element but placeholder-enhanced adds a class to input and then sets value to placeholder text. Both have positives and negatives. I can see why there are less positioning issues with placeholder-enhanced since it doesn't have to figure out the current location of the element to position a new div on top of it.

But the one thing i found interesting was that for password fields, placeholder-enhanced creates an input on top of the password input. Its a clever idea but i found a bug with IE9 (go figure) that by default password inputs w/out size have a set width. I need to patch the placeholder library to check for size of the input that it covers up. I've forked and submitted pull request on github.

The only other thing i'd like with placeholder-enhanced is way to disable adding 'placeholder' class to input elements when browser supports placeholder styling since we don't need that. It should be too tough to create new parameter. Someday :)


Tuesday, October 4, 2011

Dancer::Plugin internal sharing

I've been creating quite a few Dancer plugins recently. The nice part of a Dancer plugin is that it gives a small new set of keywords.

In some cases, I've want to provide a generic keyword interface to an object but then provide smarter business level keywords. I've found a quirk in the Dancer::Plugin interface. I couldn't find it documented anywhere but I'm sure it is.

If you want to access keywords from the same space that they are registered you need to use a different format than the:
register keyword => sub {};

You need to use the pattern:
sub keyword {
  # do stuff

register keyword => \&keyword;

register_plugin actually stuffs the symbols into the namespace therefore you need to share the sub names before that happens to use them.

Wednesday, July 13, 2011

Perl Module Versions in dotcloud

I just realized that I was running an older version in my dotcloud service. There was an update due to a security issue so it was kind of important.

I found that I needed to update (or put) a version number in the Makefile.PL. Here is an example of mine.

use strict;
use warnings;
use ExtUtils::MakeMaker;

    NAME                => 'leecarmichael',
    AUTHOR              => q{Lee Carmichael },
    VERSION_FROM        => 'lib/',
    ABSTRACT            => 'Home Site',
    ($ExtUtils::MakeMaker::VERSION >= 6.3002
      ? ('LICENSE'=> 'perl')
      : ()),
    PL_FILES            => {},
    PREREQ_PM => {
        'Test::More' => 0,
        'YAML'       => 0,
        'XML::RSS'   => 0,
        'URI'        => 0,
        'Date::Parse' => 0,
        'Digest::MD5' => 0,
        'Plack'       => 0,
        'Plack::Request' => 0,
        'Template'       => 0,
        'Dancer'         => 1.3040,
        'Dancer::Plugin::MobileDevice' => 0,
        'Dancer::Plugin::Email'        => 0,
        'Dancer::Plugin::FlashMessage' => 0,
        'Dancer::Plugin::Database'     => 0,
        'Dancer::Plugin::XML::RSS'     => 0,
        'Dancer::Session::Storable'    => 0,
        'DBI'        => 0,
        'DBD::mysql' => 0
    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
    clean               => { FILES => 'leecarmichael-*' },

My updated one has version of Dancer changed to:
'Dancer' => 1.3060,

I like this approach to module version management. If you want to force the system to move to everything new you'd need to delete your service and recreate then push. If you want to force just a single CPAN module up to the most recent you update the version number.

It probably will require me to create a script to compare versions between the service and local dev/qa machines. Better put that on the TODO list :)


Making sure dotcloud serves static files not Dancer

Dancer is a great framework. It does a great job making a default development work out of the box. Its a nice alternative to some of the heavier ones that require quite a bit of setup (actually most Perl web frameworks do a great job of this).

Also it makes sure to serve static content (to avoid deployment issues, I assume). But compared to nginx or apache it is much slower at serving this (not a big surprise). In my dotcloud deployments I've found this to be a bit confusing to make sure nginx handles it instead of Dancer.

My first pass at this was setting up these symlinks in my source tree:
static/css         --> ../public/css
static/javascripts --> ../public/javascripts 
and such.

It felt wrong to have this inside source control so I dug around a bit and ran into the postinstall script that is supported by the deploy dotcloud command option.

I added the following link commands to mine to create those nice symlinks:

# used for dotcloud deployment

# setup static symlinks
ln -s ../public/images static/
ln -s ../public/css static/ 
ln -s ../public/javascripts static/
ln -s ../public/favicon.ico static/favicon.ico

Nice, pretty and only used for dotcloud deployments.


Friday, May 20, 2011

nginx include(s)

As part of my ongoing exploration with dotcloud, I've had to do a bit of learning about nginx.

I've never worked with nginx before but i needed to add some rewrite rules into my dotcloud deployment. I wanted to make sure that static content like images and css files where being served by the nginx instead of my app (Dancer is pretty nice about making sure public content gets served during requests).

I found that after changing a nginx include that the server needs to be restarted or reloaded after a change to the include. I spent a few hours trying to figure out if a restart was required since I wasn't sure if I had screwed up the rules due to a bug (now fixed) with dotcloud deployment not restarting it after a push as expected for Perl deployments.

dotcloud provides server restart as: udo /etc/init.d/nginx restart


Wednesday, May 18, 2011

My First Custom Dancer app deployment on dotcloud

I'm in the process of rewriting my site I really wanted a reason to build a small but real app with (Perl)Dancer.

I really like most of Dancer's approach to routing and layout. It fits well with my way of thinking of web apps. At the same time I stumbled onto Dot Cloud, a very well thought out and incredible nice deployment provider. They are part of the current cloud shift in which individual application stack layers are hosted instead of a full OS stack.

Here are the few gotchas that I found:
  • They deploy using PSGI and Plack, very cool. But its deployed with an environment of 'deployment'. This means you must have a deployment configuration file. Example: application_root/environments/deployment.yml. I found this confusing since i expected it to follow the Dancer approach of production (my own bad assumption)
  • Unfortunately, runtime errors are not logged to the standard web server error log (or anywhere else). Therefore you need to turn on core logging to find serious errors. I did this by adding the following to my config: debug:"core". ( I am opening a bug :)
  • Lastly I needed to add DBD::mysql to my Makefile.PL (which is really a great way to handle dependancies for deployment). I overlooked this since it was hidden in my app since its not directly 'use'd. (so much for being smart with: ack use --perl :)

Next on my list is to use the Aliases feature to completely move the site and I need to figure out how to exclude subversion meta files from dotcloud push. But first I need to work on the editing part...

Then comes:
  • Custom 400/500 pages
  • Changing header images
  • other fun stuff


Friday, May 13, 2011

Using Dancer's Request HTTP Env shortcuts

As I was working on a small application that allowed editing of pages, I really wanted to grab the referring page to redirect after the page was updated or the edit session was cancelled by the user.

It wasn't very clear to me how to grab the referer from Dancer's POD documentation on Dancer::Request.

Basically I could grab it either of 2 ways.
  1. request->referer - nice. This applies to other env options as well forwarded_for_address which pulls in X_FORWARDED_FOR
  2. request->env->{HTTP_REFERER} - feels more lower level.
I read the documentation as request->env->{referer} which is not correct at all.

In the end it is much easier and I think prettier than the several options I tried :)


Thursday, May 5, 2011

Dancer and TT config

Quick note to self (and anyone that might be listening): When setting config options different than start and end tag for TT such as PRE_PROCESS in Dancer, you must make them all caps.

e.g. config.yaml:
# template engine
template: "template_toolkit"
     encoding:  'utf8'
     start_tag: '[%'
     end_tag:   '%]'
     PRE_PROCESS: ''

Tuesday, January 4, 2011

Subversion import bites me

I often work on new projects outside subversion tree then move them in at some reasonable point. This usually avoids conflicts inside the group, sometimes it involves an evolving idea or a new template may need converting before updating reducing some noise.

It is important to remember with svn import is that you need to specify the end location of the directory in the tree.

Well I often forget this and its a pain since I haven't found a good way to undo it without just removing or moving all the crap by hand :(

a few examples:

svn import new-theme

Then recheck it out:

svn checkout ~/proj/projectx/webapp

Or you can import new stuff into an existing location:

svn import a-few-new-files