cnp_studio (cnp studio) - An interactive division of Clark/Nikdel/Powell

A unique mix of technology, creativity and human interaction makes cnp_studio a Web development firm focused on connecting people. Creating simple, useful Web sites is what we do. Learn more about us.

cnp_studio Blog

cnp_studio Blog

Archive for the ‘Development’ Category


SQL Server Side Paging

Friday, February 29th, 2008

I was extremely excited about GridViews and DataGrids when I first started working with .NET. The thought of having controls with built in paging and sorting just blew me away. Needless to say, this excitement was short lived. By the end of my first project in .NET, I found that this built in sorting and paging had some major performance issues. It was too much data to send back and forth between the web server and the SQL server; not to mention that .NET just isn't as optimized to sort that much data as fast as SQL Server.

The alternative was to have SQL Server sort and page the data and only send back the data that was needed to the web server. After some research and some time to combine the ideas I found into my own solution I came up with:

 
CREATE PROCEDURE dbo.ReturnPage
(
  @SelectStmt varchar(1000), --Select Statement with Where Clause
  @OrderBy varchar(1000), --Order By Clause 'ASC' is required
  @StartRow int, --First Row of Page
  @EndRow int, --Last Row of Page
  @totRows int output --Output: Total Rows in Set
)
AS
 
DECLARE @ColList varchar(2000)
DECLARE @WhereCls varchar(2000)
DECLARE @i int
DECLARE @i2 int
DECLARE @tmp varchar(1000)
DECLARE @dec varchar(1000)
DECLARE @f varchar(100)
DECLARE @d varchar(100)
DECLARE @Symbol char(2)
DECLARE @SQL varchar(4000)
DECLARE @Sort varchar(1000)
DECLARE @tmpSQL NVARCHAR(4000)
 
--Assign the total number of rows available to @totRows for output
SET @SQL = N'SELECT @totRows = COUNT(*) FROM (' + @SelectStmt + ') tbl'
SET @tmpSQL = '' + @SQL
EXEC sp_executesql  @tmpSQL , N'@totRows int OUTPUT',
     @totRows = @totRows OUTPUT
 
SET @Sort = @OrderBy + ', '
SET @dec = ''
SET @WhereCls  = ''
SET @SQL = ''
 
SET @i = charindex(',' , @Sort)
 
--Pull apart the sort by clause for declarations
WHILE (@i != 0)
BEGIN
  SET @tmp = LEFT(@Sort,@i-1)
  SET @i2 = charindex(' ', @tmp)
  SET @f = ltrim(rtrim(LEFT(@tmp,@i2-1)))
  SET @d = ltrim(rtrim(substring(@tmp,@i2+1,100)))
  SET @Sort = rtrim(ltrim(substring(@Sort,@i+1,100)))
  SET @i = charindex(',', @Sort)
  SET @symbol = case when @d = 'ASC' then '>' else '< ' end +
          case when @i=0 then '=' else '' end
 
  SET @dec = @dec + 'declare @' + @f + ' sql_variant; '
  SET @ColList = isnull(REPLACE(REPLACE(@colList,'>','='),'< ','=') +
    ' and ','') + @f + @Symbol + ' @' + @f
  SET @WhereCls = @WhereCls + ' OR (' + @ColList + ') '
  SET @SQL = @SQL + ', @' + @f + '= ' + @f
 END
 
--Put together Transact SQL for final output
SET @SQL = @dec + ' ' +
  'SET ROWCOUNT ' + convert(varchar(10), @StartRow) + '; ' +
  'SELECT ' + substring(@SQL,3,7000) + ' from ('
  + @SelectStmt + ') a ORDER BY ' +  @OrderBy + '; ' +
  'SET ROWCOUNT ' +
  convert(varchar(10), 1 + @EndRow - @StartRow) + '; ' +
  'select * from (' + @SelectStmt + ') a WHERE ' +
  substring(@WhereCls,4,7000) + ' ORDER BY ' + @OrderBy +
  '; SET ROWCOUNT 0;'
 
EXEC(@SQL)
GO
 

What's it doing?

The procedure works by turning a simple query like:

 
SELECT col1, col2, col3, col4 FROM TABLE ORDER BY col1 ASC
 

and turning it into the following to add the paging.

 
DECLARE @col1 sql_variant
SET ROWCOUNT = @StartRow
SELECT @col1 = col1 FROM TABLE ORDER BY col1 ASC
SET ROWCOUNT = (@EndRow - @StartRow) + 1
SELECT col1, col2, col3, col4 FROM tbl WHERE col1 > @col1
  ORDER BY col1 ASC
 

Simple enough right?

Disclaimer

While this procedure does work with more complex queries containing SUB-SELECTS, JOINS and WHERE clauses, it does have its limitations. GROUP BY clauses do not work in this version. Maybe in the future.

I wouldn't suggest calling this procedure directly as that would mean you're building your query in-code, and probably not doing necessary escaping to prevent security issues. Creating a stored procedure that builds the original query from passed in WHERE and ORDER BY Parameters and then calls the ReturnPage procedure will be much more efficient and secure.

I hope to post a complete sample that will illustrate the changes to the .NET code and the wrapping procedure soon.

2008 Local Addy Awards

Tuesday, February 26th, 2008

This past Friday everyone from the CNP offices attended the local Addy Awards banquet to see what kind of awards we would walk out with this year. The Addy Awards are conducted by the American Advertising Federation and the local competition is the entry point to their national competition. Awards are given across a multitude of categories from printed newsletters to TV commercials, product packaging to web sites.

Addy Awards
Photo by Sean

Basically, how it works is that we submit our best works from the previous year to the local competition and based on several criteria are awarded a gold award, silver award or nothing. Anything that is awarded a gold at the local level is then sent on to the state competition for the next round. I'm pleased to say that at this year's competition we had four of our submissions receive gold and they will move on to the next level. They were:

cnp_studio (one gold for the web site, one gold for our logo/stationery/business cards)

cnp_studio Web site

SeaWorld Journey to Atlantis

SeaWorld Journey to Atlantis

Kelly Homes

Kelly Homes Web Site

The award on the Kelly Homes site is bittersweet. We're glad the site did well, but sadly the entire site design as well as the HTML and CSS behind the site were completely copied and used by someone who thought it was OK to do such a thing. Expect to see more on this in another post here.

Sites receiving silver awards include Girl Scouts of West Central Florida, Polk Transportation Planning Organization, TrueDemand Software and Heacock Classic Car Insurance.

All of this is a result of the hard work of an all star team (Mike, Pete, Sean, Jeremy) and our great clients.

Veni, Vidi, Voce - We Came, We Saw, We Partnered
Sony Gives Back to WordPress

Wednesday, February 6th, 2008

It seems that we've got a recurring theme in our portfolio. That is, development on social media projects for some really big brands. They're a product of the amazing vision of our good friends at Voce Communications mixed with the talent of our developers here at cnp_studio. IMHO we've made some beautiful music together and thanks to the incredible people involved we get to share some of that with everyone. Now, where to start?

Partnership

You know what it's like when someone gets you and you get them? You get one of those "Where have you been all my life?" feelings? That's what it's been like working with Mike, Josh and the others at Voce on these projects. To say they understand the industry is an understatement which is why I'm extremely excited to announce that we're officially partnering with Voce for all things social media. Consider the gap between strategy and implementation bridged. This really is only a formality for what has already been a great relationship. We're stoked to make it public. Read more from Voce's side of things here.

Plugin Release

So for PlayStation.Blog we've done quite a bit of customization to the WordPress install on the site. We use several existing plugins on the blog including WP-Polls, WP-Cache, WordPress Download Monitor and others. A couple of needs though left us without a plugin to fill the void. So, we created our own. And it's because of the great people at Sony and Voce that we get to release these plugins back to the WordPress community. Sweet.

Image-Rotator Plugin

If you look at the homepage of the PlayStation blog you'll see a main image header that they use to promote any number of things. We had originally created a simple manager to allow them to quickly upload these images and set a URL where the image should link, but they wanted to take this one step further and release it back to the community. Who were we to argue? So with some tweaks we made it into the plugin that you can read about/download here. Install it, add the line of code where you'd like the rotation to appear and you're set (oh and don't forget to add some images).

Author Comment Reply Plugin

The threaded comments plugin existed, but nothing that limited it strictly to authors replying to comments. Our fear, especially in the case of the PlayStation blog, was that the threaded comments would get out of hand. That, and it's not a discussion board, so we wanted to avoid that feel. This plugin allows authors to keep their response tied directly to the comment they're replying to without having to put the "@name" in order to reference back to previous posts. If you have a high volume of comments on your blog you'll find this one helpful. Read more about and download it here.

New Site: Yahoo!’s Corporate Blog, Yodel Anecdotal

Sunday, January 13th, 2008

Friday was a fun day spent at the Yahoo! campus in Sunnyvale, CA launching the updated Yodel Anecdotal. Myself along with Mike and Josh from Voce Communications got together with Nicki Dugan (Yodel's Editor) to add some more cowbell.

Things started with a meeting on the redesign back in late July 2007 and led to what you see today. Some of the updates included in the upgrade are:

  • Updated Design: A completely new look was created and a big thanks to Jeremy for yet another great one. This helped to allow for now more room within the post body as well as a wider sidebar. We feel that it gives things more room to breathe.
  • E-mail Subscription: In addition to the RSS feed available an e-mail based subscription to post updates is available
  • Tagging: Tagging has been added to help better identify content. Now Nicki has the fun responsibility of going back and adding tags to previous posts on Yodel. Fun!

Pete and Sean took care of all CSS as well as WordPress integration. Mike developed the Image Rotator plugin that you see at work in the header of the new blog (more on that coming soon).

Here's some shots of the old site as well as the new for comparison. As always, you can also check the portfolio for more info on the project.

Old Yodel

Old Yodel Screen Shot

New Hotness

New Hotness

Conference Wrapup: An Event Apart, San Francisco

Thursday, October 18th, 2007

It's been a busy few weeks, to say the least. The end of the year crunch is always the worst. It's been nearly 2 weeks since I attended An Event Apart in San Francisco. An Event Apart is headed up by Eric Meyer, CSS Guru and King, and Jeffrey Zeldman, Founder of A List Apart and Happy Cog.

Alcatraz
Alcatraz Island, nothing to do with the conference, I know, but still cool to see.

The conference was a great experience, and I gained a lot out of it. So I thought I'd put together this list of 10 things I learned, will carry with me, implement and [attempt to] teach others. I could easily come up with more than 10, but if I gave away more information it would be like revealing the ending to a good movie that you haven't seen yet. An Event Apart is just something you have to see/experience for yourself. Most of the items pertain to "An Event Apart" and some just to being in San Francisco, and the people we met.

Without further ado, and in no particular order: 10 Things I Learned While At 'An Event Apart' in San Francisco.

1. If you have ever seen Michael Moore's 'Bowling for Columbine', you'll recall a scene in which Michael Moore randomly visits a few homes in Canada. He walks right into the front doors, which are unlocked, and is greeted by friendly people. He also shows clips from the evening news which appear to be positive and upbeat (I believe the story was about a local town installing speed bumps). Dave Lockhart, a .NET developer that Nick and I met from Desire2Learn says that this is true - which I found just completely fascinating.

2. A way to make vertical/horizontal bar graphs strictly using CSS. No flash with XML fed into it. As a developer, I seldom have to worry about the CSS aspect of a project - but this is definitely a useful trick to have on the tool belt.

3. Jeffrey Zeldman gave a great talk about 'copy'. The different types of copy - 'guide' and 'copy' copy. Guide copy can be things like directions to sign up for a service, or instructions to guide you through navigating the site, or completing a task while browsing a site. 'Copy' copy is the content that can be found on pages, like an "About Our Company" page.

One of my favorite quotes "Design helps people read less, and when people read less, every word counts". Brevity and clarity are paramount, but slightly less enforced when talking about 'copy' copy. Web users are most often in "find" mode, and thus scan the page for information. No one wants to scan a sea of content that is not relevant to the company or what the user may be on the site trying to locate in the first place.

Consider the audience. If you're writing content for a site about an a hotel, chances are no one browsing the site is going to read the full 1,200 word essay you wrote about the history of the area the hotel is in.

4. Other firms, teams, and individuals have the same triumphs and pitfalls we do. I could take up this whole page and list some of what those are here, but suffice it to say that it's nice to see we're not the only ones with some of these troubles. Not that I doubted it, but it's easy to get wrapped up in the microcosm that is our office and our work-load and forget about what's going on out there.

5. During one of the breaks, I met Zack Schneider of Schneider Digital based out of my birthplace; Buffalo NY. We shared a lot of ideas, horror stories, and talks of "cool" things to do in Buffalo. Then he told me something that is so simple and easy that it makes me wonder why I didn't think of it earlier. So it's going to be a new policy here at cnp_studio.

We will not begin design until we receive all the copy to be placed on the site.

Wow. Simple. Beautiful. It has happened all too often. Projects where we plan, design, receive approval on that design, cut up, implement, stage, and then boom - nothing. The staged site will sit there - plenty of blank pages, but no content. My own little Duke Nukem Forever projects. Months, and yes sometimes even a year later things are finally ready to get started on that project again. You're knee deep in other projects now, and of course it's needed yesterday because hey, it's time to go NOW. Then I pull the project out of the dusty subversion archives and re-familiarize myself with it. Frustrating.

Facebook HQ
Facebook head-quarters in downtown Palo Alto.

6. Unfortunately, people still use Internet Explorer. I'm a developer first, and someone who needs to work with CSS second, but Eric Meyer's talk about IE7 and CSS was very insightful. In addition to learning about visual link typing, selectors, and a little bit of form styling, Eric also shared a JavaScript library that makes IE 6 behave more like standards compliant browsers, (yes, I know Nick also mentioned this!).

7. Forms. I hate forms, styling forms, and testing the styling of forms across the different browsers. Aaron Gustafson gave a great talk with a more "hands-on" approach to quickly creating a great looking form that will definitely alleviate some of my troubles. Aaron also provided screen shots of how the various browsers treat elements like buttons and select drop-downs.

8. Jeffrey Zeldman wrapped up the conference on the 2nd day with a great talk on "Selling Design". A lot of what he said sounded great. "Avoid bad clients", "Learn to smell trouble". If a client doesn't have time to complete a simple questionnaire because they are in a hurry, or "need a proposal ASAP", then you should probably steer clear of them. They end up being nothing but trouble. This all sounds well and good, but it's not as easy for a smaller firm like us to turn away work - no matter how much trouble we smell.

He also made a lot of great points about how to sell your design to the client, and not just hand it over to them and say "So, what do you think?". This will leave you with a lot of room for them to tear the concept apart, instead of providing insight as to why things are placed where they are, the color they are, etc.

9. "Your emergency is not my problem." Enough said. But, it's also in the delivery. Lets say a client calls me and says "Listen, I screwed up, I need this up on the site as soon as you reasonably can. Whatever you can do to help me, I would more than appreciate it." A little self-deprecating humor wouldn't hurt either - "I know I screwed up and I'm an idiot!" - but it's not necessary. I digress, what I'm trying to say is that I would bend over backwards for that client to get them what they needed.

If you call me and say "I need this up there now, I know I e-mailed you about this last week (lie)" and they use words like "ASAP" or send you "high-priority" e-mails, or doctor up their e-mails to their bosses to make it LOOK like they e-mailed you last week - guess what? I just moved you to the bottom of my priority list somewhere below "alphabetize Firefox bookmarks".

I understand clients make our world go round. I do. They pay the bills. They make it all possible. Doesn't mean I'm your doormat.

10. Joyent is awesome. We use Joyent Accelerators to host any of the Rails apps I do here at cnp_studio. While Nick and I were out in California, we met up with Kristie Wells and Jason Hoffman from Joyent and had a good time over tacos and beers [If you're ever in San Francisco check out Nick's Crispy Tacos]. It's nice to see the faces and personalities behind the support tickets and forum postings.

JoyentBadge

If you ever get the chance to go to An Event Apart, definitely take it. Whether you design, develop, both or neither (and just want to learn about what's going on in the industry, best practices, ideas, etc.) there is a lot that can be gained by going.

Florida Creatives Happy Hour - More Socializing (beer) with Central Florida Developers

Wednesday, October 17th, 2007

This past Monday I attended my first Florida Creatives gathering. The group has been meeting for nearly a year now (better late than never, right?) but are very open to newcomers. It's a great excuse to get together with some like-minded designers/develoeprs for some beer and tater tots. Interested? Learn more at the Florida Creatives Web site. They meet on the third Monday of each month at the Crooked Bayou in downtown Orlando.

Florida Creatives at Crooked Bayou
Thanks to Josh for the photo and the urging to attend the meet-up.

Conference Wrapups: BarCamp Orlando, BlogOrlando and An Event Apart

Friday, October 12th, 2007

The blog continues to suffer as things stay busy at the office. In the past three weeks in addition to launching a new site (full post and portfolio pages still to come) we've been to BarCamp Orlando, blogorlando and then finished things up with a trip out to San Francisco to this year's final An Event Apart. All events definitely had their own unique offerings.

BarCamp Orlando Attendees
BarCamp Orlando - Thanks to Hyku for the photo.

BarCamp Orlando brought together a collection of developers that I don't think the event organizers expected. Any time you can bring together developers in an environment where there's plenty of beer it's a good day. Since with BarCamp you never know what you're getting until you get there and see who has signed up to talk the material was a toss-up. For me, one of the interesting takeaways was needsharing.org. Definitely an interesting take on matching donors with those in need. My father-in-law is the president of the United Way of Central Florida so it's even more interesting to compare the approaches.

BlogOrlando, headed up by our buddy Hyku Hallett brought together some of the same people from BarCamp, but added a much larger audience of local Public Relations professionals. We hardly consider ourselves bloggers here at cnp_studio, but we do quite a bit of work with them and can't help but hack up and have some fun with a WordPress install. After the keynote by Shel Israel, the "Tech" track was where we spent most of our time. Mark Jaquith gave us some new information on the highly anticipated WordPress 2.4 and Jeremy Harrington from crawlspace gave some great design resources via his ma.gnolia links page. When Jeremy was told by an attendee that they had their logo designed through a contest on their blog a somewhat bewildered Jeremy was quick to ask "Would you have done the same with the roof on your house?" Thanks for fighting the good fight Jeremy. Then it was a deviation over to the hyperlocal blogging talk by Tommy Duncan, the author of Tampa's hyperlocal blog Sticks of Fire. All in all a great, worthwhile day.

An Event Apart
An Event Apart San Francisco, CA

Then it was off to An Event Apart out in San Francisco. The main thing you need to know about An Event Apart is that if you're a Web Developer and you haven't been yet, you need to go. Jeffery Zeldman and Eric Meyer put on a heck of a conference. This was my second An Event Apart and while there were a few overlaps, for the most part it was great new content. Sean was in attendance at this event and I will let him put his thoughts together so as to prevent he and I posting the same thing. One thing of particular interest from the conference though... for those of you experiencing those IE6 pains (that would be everyone) be sure to check out this javascript file that helps make IE6 behave like IE7.

New Site: TrueDemand Software

Monday, September 17th, 2007

Well, allow me to apologize for the blatant neglect of this blog over the past 3 weeks. I won't make excuses for not having a post since August 27, but I will say that things have been a tad bit busy around here. Quite a few sites are all coming in for a landing right now, so it keeps us on our toes. Not to mention we have officially started the end of the year crunch around here. Every year like clockwork as soon as it is September things don't let up until the middle of January. So far, 2007 has been no exception.

All of that is besides the point, though. I'd like to take a second to announce the launch of a new site for TrueDemand Software. Our main role at this point of the project was updating the site's user interface while simplifying the message. Additionally, we have created new promotion landing pages to allow TrueDemand to quickly and easily promote their solutions. This is just the start in many new initiatives for TrueDemand, so check back often!

TrueDemand Software Homepage

TrueDemand Software Interior Page

TrueDemand Promotion Page

BarCamp Orlando & BlogOrlando… We’re Going!

Monday, August 6th, 2007

It looks like September is a good month for blogs and developers in and around Orlando, Florida. Registration opened up today for BarCamp Orlando so Sean and I hopped on that (Pete and Mike are still clearing their calendars), but then it prompted me to also register for another "un-conference" coming up in September, BlogOrlando.
BarCampOrlando - We're Going!BlogOrlando - We're Going!

More on Barcamp

BarCampOrlando is a bi-yearly event to bring together people from different technical backgrounds to share and learn from each other. There will be people who know Java, .NET, Ruby, PHP, and other technologies coming together for a free all day event.

It's a day of developers sharing with other developers. There is no specific format for the day, but you are asked/expected to talk about something relevant and of interest to you. We'll definitely be contributing to the conversation and now starts the challenge of exactly what it is we'd like to talk about.

More on BlogOrlando

BlogOrlando is now in its second year and according to their site

We hope to bring together a good cross-section of folks to discuss blogging, podcasting, public relations, social media, citizen's journalism and other related topics

Josh has put together a nice list of session leaders which has us excited for a solid day of blogs.

So will we see you there? The price can't be beat on either event (they're free)!

:attachment_fu and Amazon’s S3 For File Uploading

Monday, July 30th, 2007

Most of the Rails sites I have been developing lately have been using a plugin called attachment_fu by Rick Olson - one of the core developers of Rails. attachment_fu is easily and effortless - allowing me to add the ability to add "attachments" or uploads to any model within my application. After reading the excellent tutorial by Mike Clark, I was up and running in no time.


class Download < ActiveRecord::Base
  has_attachment :storage => :file_system,
    :path_prefix => "/public/downloads/",
    :max_size => 30.megabytes
end

And in my view(s):

 
<td class="input_field">
  < %= f.file_field :uploaded_data %>
</td>
 

But after a while, downloads started to build up in size consumed, and backups were using valuable bandwidth (since backups moved the files off the server). I remember reading on the excellent tutorial by Mike Clark how easy it looked to change the storage to use Amazon's Simple Storage Service (S3). I installed the AWS::S3 Ruby library, and even played around with s3sh - the interactive shell utility that comes with the AWS::S3 library.

Revisiting the tutorial, I changed my Download model to:


class Download < ActiveRecord::Base
  has_attachment :storage => :s3, :max_size => 30.megabytes
end

And created my config/amazon_s3.yml configuration file:

 
production:
  bucket_name: my_bucket
  access_key_id: XXXXXX
  secret_access_key: XXXXXX
 

After a few quick tests, everything was working perfectly. Now the only problem I had was moving the existing downloads into the S3 account. I figured the best way to go was to integrate a rake task to help me out.


desc "Move all downloads to Amazon's S3"
task :move_to_s3 => [:environment] do |e|
  require 'rubygems'
  require 'aws/s3'

  AWS::S3::Base.establish_connection!(
    :access_key_id     => 'XXXXXX',
    :secret_access_key => 'XXXXXXX'
  )

  Download.find(:all).each do |d|
    AWS::S3::S3Object.store("/path_on_s3/to_new/download",
      open("/path/to/where/current/file/is_located"),
      'my_bucket',
      :access => :public_read)
  end
end

All done. Total cost to move all this stuff over to S3 was about $.10 .

Also, if you're interested, check out S3Fox - a plugin for Mozilla Firefox that allows you to browse, organize, and store your files into your S3 account - all through Firefox.

Latest Comments

andrew:
hey mike -- thanks for the reply, let me clarify what i mean.... I know that PHP fu...

nick:
Hi Jeff, Thanks for the heads up on the link. It's all fixed now and you should...

Jeff:
I would love to try your plugin, but the download link appears to be dead again. Ca...

mike:
@Denise: 1. The image is selected randomly each time the code is run. So normally ...

andrew:
hey -- great plugin and would like to use on several different pages, not just the ...

Categories Archives