| Subcribe via RSS

Disable timthumb PHP script

May 18th, 2009 | Comments Off | Posted in PHP
I have a blog template that I’m using for one of my sites (Scarlett for those who are interested), and it has this cool PHP script built in that will take your image files and dynamically resize them to fit a specific dimension you’ve set on your webpage. Well it would have been cool at least had I got it working. Godaddy seems to have some real issues in allowing the script to write out the temporary image files. It just leaves nice little blank spots where the image is supposed to be. Now I’m a savvy developer and have no issue concerning producing a couple different size variations of my images to load up to the server. What I need is to disable the timthumb script from trying to intervene. Here is some sample code where we are employing timthumb:

Here is that same code where we extract that script reference:

Tags: ,

Filter Gridview via DropDownList & Search TextBox in ASP.NET

May 14th, 2009 | Comments Off | Posted in ASP.NET

Have you ever developed one of those systems users just seem to love to use? I’ll admit its a good problem to have, yet they just pile on the records one-by-one until your small band-aid system starts to collapse under its own lack of usability. A few years back, I created a graphics manager program for the marketing crew to keep track of their myriad of buttons, banners and general digital assets. I let the graphics guys drop the image in the appropriate folder that corresponded to an image category then the management system sifted through those folders to show what was there. Simple right? Wrong. Three years later, it is a mess of mammoth proportions. You can’t find anything, and its almost not like having anything to manage these resources at all.

So I’ve decided to database all these resources by associating them with categories, keyword tags, image dimensions, and title/description. So the question becomes how to let the users sift through all these new fields without the interface getting bogged down in the clutter? The system’s default page is a gridview listing all the graphics that currently in the system. Along the top, I’ve place two dropdownlist controls and a TextBox control. The dropdownlists will allow me to filter the grid based on the category and/or dimensions of the control, and the textbox will allow me to do specific searches on a given term for even greater specification.

So lets take a look at the ASPX side of things. Below we have the GridView. I’ve cleaned up the code to focus on the essential elements. Nothing out of the ordinary here. Just your basic SqlDataSource feeding back the relevant fields to the GridView.

Now let’s checkout the Header elements that will serve as our content filters. Same as the Gridview, nothing special here just filling out our datasources.

So if our ASPX is so plain Jane, where is all the fun happening? The codebehind of course. All the SelectIndexChanged and Search_OnClick functions reference the same method — parseFilters. Essentially we are doing the same thing whenever a user makes a selection.

parseFilters just does a survey to see what is in each field to build the conditional filter. Whenever one of these boxes is set to something other than the default, we tack that value onto sCondition. Once we’ve stepped through each possibility, we set the FilterExpression of our GridView’s SqlDataSource equal to sCondition.

That’s all there is to it. One hangup to be aware of. If the GridView comes back blank, it means that no selections met your search. If you are sure there are variables that should be getting served up, take advantage of that Response.Write of sCondition I have included to see what exactly is getting passed back to the Datasource. It can save you lots of time wrapping yourself in frustration.

Now you have a nice, simple way to drill down on your data so your users can find exactly what they are looking for with minimal effort.

Tags: , ,

Disable Automated Line Breaks in WordPress – wpautop

May 12th, 2009 | 1 Comment | Posted in WordPress

Sweet Jesus this was way harder than it should have been. So I’ve been using Alex Gorbatchev’s SyntaxHighlighter (highly recommended to all the blogging coders out there by the way) to make my code look all pretty — preserve tab spacing, notch line numbers, color code everything nicely. It worked great except for one thing. Whenever I would have a line break it would insert a <br> tag following the line which would subsequently annoyingly show up in my code. It didn’t matter if the enter was hit in the WYSIWYG or in the HTML view, they always got added. It became a tad bit infuriating because nothing I did would stop this madness.

After much research, I discovered that WordPress has a function called wpautop which formats the page at runtime and inserts these unwanted tags all over the place. Its a great feature for the non-programmers out there, but there should be an easy way to shut it off for the rest of us. Thankfully for my sanity and yours, Urban Giraffe has created a plug-in that will disable wpautop. I tossed it into the mix, and it worked like a charm. The only GOTCHA is the logical one. WordPress isn’t going behind you to clean up your formatting mess anymore so you’ll need to start adding the appropriate break and paragraph tags where needed. With that said, if you have a blog with hundreds…thousands of posts that haven’t been formatted properly, you may want to think long and hard to determine if its worth the extra effort its going to take to reformat all those posts.

Tags: , ,

Add Default Value in DropDownList using ASP.NET 2.0

May 11th, 2009 | Comments Off | Posted in ASP.NET

So we have a DropDownList in ASP.NET. The cool thing is, the framework gurus have made life a lot easier on us programmers in 2.0 in that the asp:DropDownList control and its cooresponding SqlDataSource control are side-by-side in design mode allowing you to wire up your DropDownList without ever touching the codebehind. It does beg the question of how to fill the default value though. Say you have some sort of personnel application, you don’t always want to default the option to Angela just because she’s numero uno in the list. We need to slide in a placeholder prior to the first name that prompts the user for action like “-Select an Employee-”. This is very easy. In the Page_Load event we are going to put the following:

Take particular notice of that last line. The AppendDataBoundItems allows the new default item to be included when we tack on the DataSource. Also note that this block needs to be wrapped in between a if (!IsPostBack) conditional to ensure that we don’t erase our user’s selection when we go to process out the selections.

For those interested in how we would have done this in ASP.NET 1.0, its basically this line of code that would come directly after the DataBind statement.

Tags: , ,

Get Filename from a File Path in ASP.NET

May 10th, 2009 | Comments Off | Posted in ASP.NET
Some things should just be simple like extracting a filename from a file path. Like suppose we have this painful URL (http://www.mydomain.com/archive/articles/techology/programming/aspnet-101.aspx), and we want to trim this down to just the good stuff, aspnet-101.aspx. Well we could always write a regular expression to cut its teeth on this or even slice and dice through it by dividing it into substrings keying off the forward slash. Though its not its exactly brain surgery, its still more effort than I want to devote to this rather mundane task. Thankfully, ASP.NET makes life easy via the System.IO.Path namespace. Specifically, we are going to focus on Path.GetFileName in the following code: Now tell me it doesn’t get much easier than that. First, we do a quick check to ensure that sFileName is a URL then we run it through the Path.GetFileName which spits back our result. Path has a handful of helpful methods for massaging those file names so give them a look. Tags: ,

Limiting Validation in on a Multi-Button Form

May 8th, 2009 | Comments Off | Posted in ASP.NET
I have an ASP.NET form where the user clicks on a LinkButton to build a comma delimited string of tags that get housed in a Label control. The only problem was when I went to click the LinkButton, all the Validation controls triggered. Once you wipe out the values from the file upload and password fields, you know this isn’t going to work. After some research, the fix is fairly simply. All the Button controls have a CausesValidation property that when set to false allows you to make updates within the form without having the validation script nag you. Tags: ,

Windows 7 Beta Online: Free Download

May 6th, 2009 | Comments Off | Posted in IIS, Windows 7

Around January, Microsoft put the latest build of Windows 7 release candidate online. It was a free download, and they’d give you an activation code that would expire in 6 months to a year. All this was an effort to recruit developers and tech professionals to assist them in their beta testing efforts. As of February, you could no longer download the software yet you could still get activation codes. Seems a little ass backwards to me, but this is Microsoft we are talking about. This morning Microsoft opened back up download of Windows 7 with their final release candidate. Get Windows 7 RC here.

I managed to get a copy to test out off the torrents a couple months ago, and I have to say I’m impressed. This is coming from a guy that was so fed up with Vista that I rolled back to XP Pro even in the face of numerous headaches and hassles. Here’s what I’ve experienced so far with Windows 7:

? The install was amazingly fast. I do have a fairly new computer, but I’ve never had an install take less than an hour from start to finish. Windows 7 was up-and-running in 30 minutes.

? The computer was ready to use right at startup. All the drivers were installed for everything — graphics, sound even printer. I’ve never in my wildest imagination thought of Windows hooking up the printer, but they did. Very cool and saved lots of time of tracking down device drivers.

? After a month, I haven’t run into any compatibility issues with programs I’m running. Every once in awhile a program will trigger the “this program may not work properly” message like Adobe Acrobat, but it seems to truck along fine.

? The look-and-feel of Windows 7 reminds me a lot of Vista without those backend headaches that consistently plagued Microsoft’s ugly step-child.

? Its incredibly stable for a release candidate. I’ve had it running for the past 3 weeks and just rebooted it because general memory leaks were causing the box to run sluggish. I have yet to see a blue screen, a system crash or anything running haywire.

? It has a nice new features set. If you are a Windows developer, IIS7 is a nice built from the ground update to IIS. I’m still winding my way through the features of IIS7. Many more features to Win7 that I’m just to lazy to get into. A few can be checked out here.

In general, Windows 7 is a great OS. After being happy as a clam on XP, they lost a lot of luster in my eyes after the Vista debacle, but they’ve clearly learned from their mistakes with Windows 7. Now for my obligatory disclaimer on loading Windows 7. If you aren’t tech savvy, just wait until the final build comes out for the public. Release candidates can be buggy and incompatible with certain softwares. If you know what you are doing, load it up and have fun playing in Microsoft’s new sandbox.

Tags: , , ,

VS Error: Visual Studio 2008 compiler could not be created.

May 5th, 2009 | Comments Off | Posted in visual studio
I tried to open an existing project I downloaded example source code for off the web and it triggered the error message “Visual Studio 2008 compiler could not be created. QueryService for ‘{74946829-37A0-11D2-A273-00C04F8EF4FF}’ failed.” Turns out we just need a quick registry edit. Pull up Run and launch regedit. Step down to HKEY_CURRENT_USER\Software\Microsoft\Visual Studio\9.0\Packages and look for the value SkipLoading. More than likely its DWORD value will be set to 0×00000001. Just update this value to 0×00000000 then try opening the project again which should give you the result you are looking for. Tags: ,

Visual Studio Templates Disappear

May 5th, 2009 | Comments Off | Posted in visual studio

I was working on building an autocomplete AJAX control. All of the sudden, things start erroring out and down goes Visual Studio 2008. The real surprise comes when I try to relaunch VS and there are no templates to choose from anymore when creating a new project. In digging through the Event Viewer we find multiple triggers of the following message: Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\VisualBasic\1033\AdoNetEntityDataModelVB_ASPNET.zip), file (ModelObjectItemVB_ASPNET.vstemplate). Invalid template element (TemplateID) value (Microsoft.Data.Entity.Design.VSTemplate.ModelObjectItemVB_ASPNET).

Turns out recovering these missing templates is an easy fix. First verify that the Project Templates still exist under c:\Project Files\Microsoft Visual Studio 9.0\Common7\IDE\Project Templates\ (may vary slightly depending on what version of VS.NET you are running).Next, you simply need to reinstall them. At the command prompt, point to the directory c:\Project Files\Microsoft Visual Studio 9.0\Common7\IDE\. Now execute the command DEVENV /InstallVSTemplates. Close down Visual Studio and relaunch. All your default templates should be here again.

Tags: ,

Forging Google Pagerank

May 3rd, 2009 | Comments Off | Posted in SEO

Anyone who owns a website and is even remotely aware of where their site shows up in the major search engines knows what Google’s page rank is. Page rank in a nutshell is how valuable Google has deemed your website to be. The thinking goes that if high page rank sites are linking to you concerning a certain topic then you must be somewhat of an authority on that subject. Though no one has the secret formula of Google’s search algorithm, it is a pretty commonly held belief in the search engine optimization community that the higher your page rank, the bigger boost Google is going to afford you in their listings.

Now it shouldn’t surprise you that where their is a system in place, there will be unscrupulous individuals out there trying to find the loopholes to allow them to exploit it for their own means. Case in point, there are always a hand full of page rank 1-6 domains for sale on eBay. While those 5 & 6 domains can be quite valuable, you need to be on the lookout for forged pagerank. How would someone forge a page rank you ask? Pretty simply actually. All you would have to do is add a 301 or a 302 redirect to a website with a high page rank and during Google’s next page rank update cycle, your site would mirror, or be slightly less than, the page rank of the site you were pointing to. Google is basically inferring that the sending site is the same as the landing site.

I see a few lightbulbs going off in people’s heads. Don’t mistake this as a quick page rank fix for your site. Once that redirect comes off your site, the page rank disappears as well. So while it may say your page rank is temporarily high, it will be wiped away the next time Google does a page rank update. Google tends to do these once a quarter so just because it looks high at the moment doesn’t mean you won’t be back at square one next month. Also if Google catches you doing this, they can remove you entirely from the search engine for breaking their TOS policies. The dreaded Google ban is never a fun thing to encounter.

So the question becomes, how do you identify these shady sites from the ones with true page rank. Your first avenue is Google itself. Check both info:www.domainname.com and info:domainname.com to see if the site in question actually points to another site in Google’s directory. Next, take a look at checkpagerank.net. Plug in the domain name and it will tell you if the page rank has been forged as well as link popularity. If the domain in question, doesn’t pass either of these checks, stay far far away. You work too hard for your money to be taken by some domain scammer.

Tags: ,