Why Even Non Developers Should Learn to Use Tools Like FireBug

Have you ever gone to a website and then a stupid popup shows up that you can not get rid of? E.g. they don’t give you a close option

firebug_1Annoying, I know.  Well with a tool like FireBug, you can actually remove that popup’s code and it will magically go away!

What  you need to do is

1) Open up FireBug (or whatever) and find the “inspection” tool

Once you click this, you can then hover your mouse over the web site to highlight certain elements.  Do this until you find the annoying box:

When you’ve got this highlighted, look back at the FireBug window and you’ll see a piece of code highlighted.  This code is what actually makes the box (sort of).   It’s actually eaiser if you select the code from FireBug and have it auto highlight the web page:


Then just right click the code and “Delete Element”.  Now the box is gone!


Now lets remove the opaque background blocking your clicks.  This is pretty simple because if you go back to FireBug, click on its inspection tool and then click anywhere on the webpage, you will be clicking on the overlay.

Just right click delete element again.  And now you can view the page and click on the links!!


Have fun with FireBug.  If you ever screw the page up, just refresh 🙂

Creating Entities from Existing Database with Doctrine 2 and Zend 2

So I’m upgrading an existing system to use Doctrine, Zend 2 and Dojo and the first step was to setup Doctrine with the existing database. I really didn’t want to have to manually code up all of the Entities so I was looking to see how I could use Doctrines tools to automate this. Here’s how:

(note, I’m using Windows)
1) Create a “tmp” directory in the root of your site

2) From the root of your Zend 2 site, run

php vendordoctrinedoctrine-modulebindoctrine-module orm:convert-mapping —–from-database xml .tmp

3) Once the .dcm.xml files have been generated, you need to tell Doctrine to use the XML driver by updating the vendordoctrinedoctrine-modulebindoctrine-module.php file:

// Add the following three statements above the last two lines
$driverImpl = new DoctrineORMMappingDriverXmlDriver(
/* @var $em DoctrineORMEntityManager */
$em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
// end of new code

/* @var $cli SymfonyComponentConsoleApplication */
$cli = $application->getServiceManager()->get('doctrine.cli');

4) Create the php entity files:

php vendordoctrinedoctrine-modulebindoctrine-modules orm:generate-entities ----generate-annotations="true"

Running Windows PowerShell as Any User

So I have a need to login to other PCs through Windows PowerShell from time to time. Just like I need to SSH to other Linux machines. Well that’s fine, I just open up PS and run

Enter-PSSession computer-name

The problem is that I’m usually logged into my PC with an account that does not have permissions to the other PC. If I run PS as a privileged user though, this isn’t a problem. (Yes, I’m sure there’s a way to pass credentials through the Enter-PSSession cmdlet, but that’s not how I solved this.)

One option was to use runas and start PS from the command line

C:WindowsSystem32runas.exe /user:domainusername C:WindowsSystem32WindowsPowerShellv1.0powershell.exe

but then you don’t get the pretty blue PS window and you’re stuck in the command line.

What I ended up having to do was write a PS script to start a PS session under a certain user:

Start-Process powershell.exe -Credential "" -WorkingDirectory "C:"

I called this ps_admin.ps1 and stuck it on my desktop. So now whenever I want to run a PS session as any user, I just click it and get the following popup

From there, I login with any user I want and get the pretty blue PS screen 🙂


Searching All Tables in a SQL Server Database for a value.

One of my IT guys was trying to write a SQL query to search for a keyword in every table and column of a particular database. There are tons of solutions out there on how to do this and from looking at what he had done so far, I decided to see how quickly I could figure out one. Ended up being about 15 minutes.

CAUTION: Probably not the fastest or most optimized solution, but fairly simple:

USE My_Database;

-- Store results in a local temp table so that. I'm using a
-- local temp table so that I can access it in SP_EXECUTESQL.
tbl nvarchar(max),
col nvarchar(max),
val nvarchar(max)

DECLARE @tbl nvarchar(max);
DECLARE @col nvarchar(max);
DECLARE @q nvarchar(max);
DECLARE @search nvarchar(max) = 'my search key';

-- Create a cursor on all columns in the database
declare c cursor for

-- For each table and column pair, see if the search value exists.
-- Look for the search key in current table column and if found add it to the results.
SET @q = 'INSERT INTO #tmp SELECT ''' + @tbl + ''', ''' + @col + ''', ' + @col + ' FROM ' + @tbl + ' WHERE ' + @col + ' LIKE ''%' + @search + '%'''

-- Get results
SELECT tbl, col, val FROM #tmp

-- Remove local temp table.

Manually Fixing / Adding Permissions to node_access Table (Drupal 6)

For some reason one of the Drupal sites that I work on for one of my clients wasn’t adding new information to the node_access table for new content being created. We noticed this because some of the results weren’t showing up in searches. (They won’t if the node doesn’t have grant_view checked.) Anyhow, I created the following query to fix this:

* This statement is just used to check how many need to be
* sync'd and can be ignored. It does let you know how many
* nodes your missing though 😉
SELECT count(*) FROM mydatabase.node n where n.nid not in (
select a.nid from mydatabase.node_access a)
and (n.type = 'content_type_a' or n.type = 'content_type_b');

* Create a temp table to insert all missing permissions.
* Note, this isn't required if you only have one access type,
* but since I three, it is necessary. This tables structure
* is just a replica of node_access table.
create temporary table s (
nid int not null,
gid int,
realm varchar(255),
grant_view tinyint(3),
grant_update tinyint(3),
grant_delete tinyint(3)

* I have three node permission groups that I have to change,
* so I will run three insert statements to populate my temp
* table. There is probably a way to combine this into one
* SQL query, but that's another days lesson.
insert into s
/* This group gets view access */
select n.nid, GID_VAL, 'term_access', 1, 0, 0
from mydatabase.node n
where n.nid not in (
select a.nid from mydatabase.node_access a
and (n.type = 'content_type_a' or n.type = 'content_type_b');

insert into s
/* This group gets view access */
select n.nid, GID_VAL, 'term_access', 1, 0, 0

insert into s
/* This group gets view, update and delete access */
select n.nid, GID_VAL, 'term_access', 1, 1, 1

* Finally add all of the missing node permissions into
* the real node_access table!
insert into mydatabase.node_access
(nid, gid, realm, grant_view, grant_update, grant_delete)
select s.nid, s.gid, s.realm, s.grant_view, s.grant_update, s.grant_delete
from s;

* You might wonder why you need the temp table, it's cause the
* where clause would return no rows after that first INSERT.
* If you only have one GID to worry about, you can forget
* the temp table step.

* Confirm you get 0 results. (No missing nodes)
SELECT count(*) FROM mydatabase.node n where n.nid not in (
select a.nid from mydatabase.node_access a)
and (n.type = 'content_type_a' or n.type = 'content_type_b');

* Remove temp.
drop table s;

Yes, you could use just rebuild all of the permissions through Drupal, but when the site has an extremely large node population, this takes hours.

Adding Column Messes Up Existing SQL View

So I needed to add a new form field to an existing application, which usually requires a new column to a SQL table. Cool, no biggie. Everything is fine and dandy until I go to SharePoint to view the external lists connected to the database, I kept getting errors about string to datetime conversion. WTF…

These external lists were reading from SQL Views, so I took a look at the content coming from the views, and about halfway through the columns everything was shifted right by one. This happened at exactly where I inserted the new column (I didn’t append it to the table). The issue is that when I created the view, I used a select * instead of implicitly stating the columns. When you do this, I guess SQL Server expands * to all existing columns to make “select a, b, c, d from table” and saves THAT as the View query. So when the “select” from view was being called from SharePoint, it was referencing the old “c” column position but now that was different. (NULL for all existing rows)

This should help you to visualize:

1) Created view with select *
2) SQL Server expanded to select a, b, c, d and saved as view.
3) Now by selecting all from view, it’s using: select a, b, c, d from myView

a | b | c | d
1 | 2 | 3 | 4

1) Added column newCol after column b
2) View now still calling using: select a,b, c, d from myView, but now newCol was being used for c, and then c was used:

a | b | c | d
1 | 2 | NULL | 3

AH d is using c column value!! So the rest are now off by one.

To fix, just ran ALTER on the view

But lesson learned, DON’T create views with SELECT *

Bottom of Two dijit.InlineEditBox with dijit.form.Textarea Editor Does Not Open on Single Click

dijit.InlineEditBox is great, but if you have two stacked on each other in containers with undefined heights, things can get a little buggy for a user. Example:

The problem is that if you open up id=”one” first, the page height expands two rows to make a textarea, so when you click on id=”two”, the page re renders and doesn’t open “two”! (This will work going from “two” to “one” since the top part of the page won’t change.)

If you watch the focus and blur events you’d see the following from “two” to “one”:

Focus: two
Blur: two
… click one
… two closes
Focus: one
… one opens
Blur: one

If you watch the focus and blur events you’d see the following from “one” to “two”:

Focus: one
Blur: one
… click two
… one closes
Focus: two
…. NOTHING …..

Basically for some reason it doesn’t open. So to fix this, just implicitly call edit() during onFocus.

onFocus: function()
this.edit(); // Force (technically it may get called twice now, oh well.)

Drupal 6 Custom Module Causes WSOD

You created a custom module and tried to setup a theme function with it. After changing an Administration setting, you get the WSOD (white screen of death) on all pages. There are no errors in the Apache or PHP error logs. This is not a memory or time out issue. You screwed up in your module 😉


# Disable your module
update yourdrupaldatabase.system set status = 0 where filename like 'sites/all/module%' and name like 'your_custom_module_groups_%';

# Remove main cache
delete from yourdrupaldatabase.cache;

# Remove all other cache tables.
delete from yourdrupaldatabase.cache_*

Now you should be able to access the site. After you remove any template references in your module code and delete any .tpl files, you can safely re enable your custom module:

update yourdrupaldatabase.system set status = 1 where filename like 'sites/all/module%' and name like 'your_custom_module_groups_%';

Cheers, strick.

Randomly Display a List of Data with JavaScript Using Singleton Pattern

Just a small object that loops through data from an AJAX request and updates the diplay every 10 seconds with a new item from the list.


var myList = (function()
var instance = null;

function init()
var myList = [];

function startLoading()
var num = Math.ceil(Math.random()*myList.length);

$('#item-title').fadeOut("slow", function(){
$('#item-title').fadeIn("slow", function(){

setTimeout(function(){startLoading();}, "10000");

return {
start: function()
// Populate objects list.
url: '/service/get-items-list',
myList = JSON.parse(data);

return {

getInstance: function()
if( !instance )
instance = init();

return instance;