Friday, December 7, 2012

Symfony 2 cache and log permissions on Ubuntu

Using the ACL, run the following in your project home directory:


sudo setfacl -R -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs

More info at http://symfony.com/doc/current/book/installation.html

Tuesday, November 27, 2012

CSS, Sublime Text 2, Colon, Vintage Mode

Can't use ':w' to save CSS/LESS files in ST2 in Vintage mode because it keeps just inserting the colon? The problem is actually with ZenCoding keybindings.

Quick Fix

Add the following to your User Confirmation file, found via Preferences -> Key Bindings (User)


{ "keys": [":"], "command": "show_overlay", "args": {"overlay": "command_palette", "text": ":"},
        "context": [{"key": "setting.command_mode"}]
    }

Note: The above should be inserted inside of the square brackets ([]).

What's going on?

ZenCoding has a default key binding for ':' that doesn't really respect Vintage mode. You can see these bindings in Preferences->Package Settings->ZenCoding->Bindings->Key Bindings (Default).

The binding mentioned in the Quick Fix is a copy/paste from the Vintage package key bindings. What we're doing here is putting it into our User key binding file, effectively over-ridding the one from ZenCoding.


Sunday, November 11, 2012

Using services.yml instead of services.xml in Symfony 2

In my application's bundle, I recently wanted to switch from using an XML file to register my services to a YML file. There's more information about services here: http://symfony.com/doc/current/book/service_container.html

Here's how to do it.

Create the services.yml file in your bundle, probably in something like /src/Acme/DemoBundle/Resources/config/services.yml

Next, edit the bundle's extension file and change which services file gets loaded:


// src/Acme/DemoBundle/DependencyInjection/AcmeDemoExtension.php

namespace Acme\DemoBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;

class AcmeDemoExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }

    public function getAlias()
    {
        return 'acme_demo';
    }
}


The main changes are:

  1. switching the XmlFileLoader to YamlFileLoader in line 14
  2. canging the file to services.yml in line 15

Saturday, November 10, 2012

Symfony 2: Drop, Create, and Update Database

The Problem

This is regarding symfony 2.1 CLI tasks. When trying to add a task that dropped, created, and updated my database, I received the following:


[Doctrine\DBAL\DBALException]                                                              
An exception occurred while executing 'SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'':  
                                                                                           
SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected                           
                                                                                                                                                                 
[PDOException]                                                    
SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected

The problem, it turns out, was that doctrine was using the same connection that it used to drop the database as it was to update the database. After the drop, doctrine lost it's awareness to your database and did not re-establish it upon create.

The Fix

You need to close the connection after calling doctrine:database:drop and before doctrine:database:update --force

$connection = $this->getApplication()->getKernel()->getContainer()->get('doctrine')->getConnection();

  if ($connection->isConnected()) {
   $connection->close();
  }


And just for reference:

Drop, Create, and Update database in Symfony 2 CLI Task



  $drop = $this->getApplication()->find('doctrine:database:drop');
  $drop_args = array(
   'command'=>'doctrine:database:drop',
   '--force'=>true
   );

  $drop->run(new ArrayInput($drop_args), $output);

  //Make sure we close the original connection because it lost the reference to the database
  $connection = $this->getApplication()->getKernel()->getContainer()->get('doctrine')->getConnection();

  if ($connection->isConnected()) {
   $connection->close();
  }

  $create = $this->getApplication()->find('doctrine:database:create');
  $created_args = array(
   'command'=>'doctrine:database:create'
   );

  $create->run(new ArrayInput($created_args), $output);

  $update = $this->getApplication()->find('doctrine:schema:update');

  $update_args = array(
   'command'=>'doctrine:schema:update',
   '--force'=>true,
   '--em'=>'default'
   );

  $update->run(new ArrayInput($update_args), $output);

Friday, July 20, 2012

Best Gnome Extensions for Developer Efficiency

Here are some GNOME Shell extensions I've found useful as a web developer. I'm using Ubuntu 12.04 (Precise Pangolin) with GNOME Shell 3.4.1.

AlternateTab


The default window switch behavior has some undesirable behavior:
  1. It spans all of your workspaces - To me, this defeats the whole purpose of a workspace!
  2. It groups multiple instances of of a program together, requiring you to press Alt-` to see the individual windows. When you're tabbing between 3 different terminals this can be annoying.
AlternateTab gives you back the old, tried and true way of doing things, with each window being represented and limiting what is shown to your current desktop.

One remaining problem... Window Switching Delay

The default behavior and AlternateTab both cause a delay when switching windows in GNOME Shell with Alt-Tab. The comment in the code indicates that this is to not bother people with a popup when they're quickly switching windows. Maybe this works great when you only have two windows open, but once you add a third in the mix, you loose the ability to see which one you're switching to.

To hack around this, you can change the initial delay in the code. In Ubuntu 12.04 (Precise Pangolin), you can change

/usr/share/gnome-shell/extensions/alternate-tab@gnome-shell-extensions.gcampax.github.com/extensions.js

Find the following block of code:
         // We delay showing the popup so that fast Alt+Tab users aren't
         // disturbed by the popup briefly flashing.
         this._initialDelayTimeoutId = Mainloop.timeout_add(POPUP_DELAY_TIMEOUT,
                                                            Lang.bind(this, function () {
                                                                this.actor.opacity = 255;
                                                                this._initialDelayTimeoutId = 15;
                                                            }));

and change this._initialDelayTimeoutId = 0

Message Notifier

I was very unhappy with how notifications were integrated with chat programs like Pidgin and Empathy. Having pop-ups continuously jumping up on the bottom of the screen on top of Vim or a terminal got old pretty quickly.

I solved that problem by setting my status to Invisible in my chat programs and disabling notifications (click your username in the upper right and switch Notifications to "Off"). This is still being discuss here and here.

I did want some kind of indication that I got a message though. Message Notifier does exactly that. A small, unobtrusive indicator in the upper indicator bar that tells me how many unread messages I have in Empathy. Perfect!

Dock


This extension adds a small dock to the right side of your screen, hidden until you mouse-over. It shows the same things that are on the left side of the screen when you Alt-F1

I rarely use this, but sometimes it makes up for not having an always-present list of running windows, like when you're Remote Desktop'd in to another computer and it's grabbing your Alt-Tabs and other shortcut keys.

Remove Accessibility


This removes the Accessibility icon from the Top Bar.

Window Navigation


This is required for any self-respecting keyboard navigator!

When press Alt-F1 to bring up your Overview, you can release and re-press Alt to place a number on each of your running windows. Pressing that number will switch the focus to that window.

It wasn't immediately apparent that you need to release and repress Alt to make Window Navigation do anything, so don't forget.

Workspace Indicator


Maybe unnecessary, but it shows which workspace you're on in the top bar. Helpful if you always use the same Workspace configuration and often forget what you were doing!


Thursday, July 19, 2012

"Amend" a tag in git


When creating a tag in git, you sometimes notice 5 seconds later that you forgot to add a file or that you introduced a small problem. This "premature tagulation" happens to me all the time.

When I initially look for how to do this, I had just read about "amending a commit", so my natural thought process was to Google for "amend a tag in git". This isn't the right way to label this, so I'm posting for anyone that's following my incorrect line of thinking.

What you really want to do is create a new tag with same name.

git tag -a my_tag_name

With no arguments, this returns:

fatal: tag 'my_tag_name' already exists


You need to force the tag, which tells git to "put the sticky label" for the tag on another revision

git tag -a my_tag_name -f 


which does what you want.