Showing posts from 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).


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. $('.special-sauce')[0].href(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: this.getTrigger()[0].hrefand had the moment of clarity that said "that really means: this.g…

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 …

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.

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; WriteMakefile( 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, 'Plac…

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 deploydotcloud command option.

I added the following link commands to mine to create those nice symlinks:
#!/bin/sh # used for dotcloud deployment # setup static s…

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


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…

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.
request->referer - nice. This applies to other env options as well forwarded_for_address which pulls in X_FORWARDED_FORrequest->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 :)


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" engines: template_toolkit: encoding: 'utf8' start_tag: '[%' end_tag: '%]' PRE_PROCESS: ''

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