Archive for November, 2011

Why is Box-Shadow Not Working in IE?

Note, this may not always be the solution, but it is the solution to something that puzzled me for a while.
The div I wanted to have the drop-shadow was inside a table which had border-collapse set to ‘collapse’.  Turning off the border collapse attribute made it work.  For some reason having that set meant that the box shadow doesn’t draw.
Mischief Managed

How to Speed up jQuery: Selector Tip

I ran into a slow jQuery selector in older browsers on a large document and learned a cool tip: jQuery selectors should get more specific from left to right. Selectors are parsed in reverse order, so making sure that your most specific selector is on the right will increase performance.

The example below shows how not to write a jQuery selector using this technique:

$('p#intro b').each(function() {
   //Do something
});

In the above example, jQuery finds all elements of type ‘b’ and then looks to see if the have a parent of p#intro.

Instead, it is recommended that you use the find function to speed up your jQuery. This took my 30,000 element document parsing time from 15 seconds to about 2:

$('p#intro').find('b').each(function() {
   //Do something faster
});

This example does the opposite, finding a elements matching p#intro and looking in their children using the find() function to find all elements of type ‘b’.

How to Use an ExpressionEngine Variable in PHP

If your stuck on how to use expression engine variables dynamically in a php script, you can assign the variable to a php variable using a certain syntax and from there conform it however you like.  First off, make sure the EE template has PHP enabled and then pass it to the php code segment in the following fashion:

...template code...
{if title}
<?php
$phpvar = "{title}";
echo $phpvar;
?>
{/if}
... more template code...

Putting Ext JS toolbar items on the right side

I wanted to add an item to a toolbar in one of my ExtJS panels but was having a little trouble. I could get them on the toolbar fine but I wanted them displayed on the right side of the panel. This was proven tricky, especially as I’m rather new to ExtJS

Then I found the “tbfill” xtype. This made it simpler than it ever could be:

var tb = new Ext.Toolbar({
        items: [{ xtype: 'tbfill' },
            {text: 'Compliment me', handler: function(){ alert('Nice...umm...hair?!'}}
        ]
    });

It’s quick tools like this that have really got me hooked on ExtJS.

How do I drop connections and detach a database in SQL Server

Frequently when moving or modifying databases, they need to be detached.  The problem with this is a database can’t be detached if there are active connections to it.

The following code snippet disconnects active sessions and detaches the database myDbName

USE master;
GO
ALTER DATABASE myDbName
SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
EXEC SP_DETACH_DB @dbname = 'myDbName', @skipchecks = 'true';
GO

I’m Speaking at IndieConf

Earlier this year I was selected to speak at IndieConf in North Carolina in a talk titled “Building a Business — Growing Beyond Indie Work.”  I’m excited for the opportunity and have put a lot of time into my talk.  An audio speaker spotlight was just released where conference organizer Michael Kimsal and I go into detail about what this talk is about, who the target audience is, and why anyone should attend.

What is this talk about?

I’m going to be speaking on what it means to grow a business and share some relevant experience around the people, marketing, strategy and finance aspects of a service related business.  Topics include stories from my own business as well as stories from associates and friends.  Stories are designed to get attendees over the hump of hiring your first employee, but to do it comfortably and successfully.

Who is the target Audience?

The target audience is anyone who currently has or intends to have a successful indie career.  It will get into the finer details of how things in an audience member’s life will change on a day to day basis as well as bigger picture changes after hiring one or more details.  It will give some tactics on how to keep risk low while building your business, how to position yourself for success and press forward without feeling like you are jumping off a cliff.

Why should anyone attend?

You should attend this talk because it will shed valuable insight into how things will change for better and for worse.  There are many things I wish I’d considered before I hired a full time employee, and this is my opportunity to share lessons learned and h0pefully accelerate others in the process.

Flash Builder: How to Add a Spark Group Background Color

Ideally, things would be a lot simpler if spark groups had a background color property that could be set.  But of course, that is not the case in Flex / Flash Builder.  However, there is a minor work around that one can follow to obtain background colors for spark groups.

<s:Group>
    <s:Rect width="100%" height="100%">
        <s:fill><s:SolidColor color="0x336699" /></s:fill>
    </s:Rect>
    <s:VGroup>
        <s:Label text="group content..." />
        <s:Label text="group content..." />
        <s:Label text="group content..." />
    </s:VGroup>
</s:Group>

Since vgroup doesn’t have a background color property, you can make a rectangle behind it to have desired background properties.  Flex also isn’t very functional with rectangles unless they are in a group of some kind. (i.e. in a scroller tag)  So that is why it’s best to wrap both the rectangle and the vgroup in a regular grouping segment. (same applies to hgroup, tilegroup, and other sparkgroups)

*NOTE: Put the rectangle first.  Otherwise the rectangle will be covering the spark group before it.  In flex, the last element being produced is placed in front of the previous item.

Getting and updating a wordpress post from permalink

We’ve been working on a plugin and we needed to get a wordpress page from a given permalink. This is actually done pretty easily since there is a function wordpress uses deep in their system.

$post_id = url_to_postid($permalink);

This will give you the post_id which you will able to use to retrieve the post object.

$post = get_post($post_id);

Now that we have the object its pretty simple to manipulate it.

$post->post_content = $new_page_content;
wp_update_post( $post );

So all together:

$post_id = url_to_postid($permalink);
$post = get_post($post_id);
$post->post_content = $new_page_content;
wp_update_post( $post );

Updated Freeform Module in Expression Engine 2 No Longer Creates Entries

Having started out with a lovely expression engine buildfound yourself needing to upgrade to the newest version of Freeform. A lot of the time this will update correctly with no errors.

However, in cases like mine, it has been perfectly described as:
“I’m getting no entries entered into my Freeform control panel, no notification email, and the redirect goes to the home page.” (source)

The solution is more than likely having to do with your htaccess file. Reading the above linked forum conversation, it appears that with this version of Freeform, your .htaccess cannot have a  rewrite command to redirect non ‘www’ requests to the ‘www’ version.  There is a work around that I used located here.  Cheers!

The difference between Decimal and Float SQL datatypes

What is the difference between Decimal and Float datatypes in SQL? Well you can accomplish the same with both but there are advantages to each.

First off the syntax is quite different.

Float(char_length)
Decimal(total_length, length_right_of_decimal)

So you can see with decimal you may get more precision as it will never round. If you need some major finance calculations, decimal is the preferred route.

However if extreme precision is not needed and you have varying lengths of decimals, floats certainly make it easier.