Random SQL Server results - a one word command

I learned a great way to randomize SQL results.

In the past, I would have followed this routine:

Run a query pulling all of the results (tens? hundreds? thousands?).
Create an array.
Loop until 5 good random results are made:
    Get 1 random query result.
    If it's not in the array, put it in.
    If it is in the array, ignore it and try again.
Then I'd output the data from the array, rather than the query.

I suppose I could simply fill an array then randomize it. But that's not really the point.

As you see, with this version we have to pull back so many more results than we're actually going to use. That's wasteful - especially if you want to pull back lots of data in each row.

So what's this great super duper new way I've discovered to simplify code, only pull back the 5 results from SQL Server, and run fast? It's really simple: tell SQL Server to do the work for you, with one word. No post parsing needed!

» Continue Reading »

WebVeteran.com based code deployed on NASA's website

Wow how cool is this?

Scriptaculous' modified version of my JS Audio Engine is being used by NASA!
EX: http://www.nasa.gov

» Continue Reading »

Emergent Success Launches ES-Extranet, an Innovative Online Collaboration Tool

SOURCE: Emergent Success, Inc.

Sep 26, 2007 14:32 ET

MOUNTAIN VIEW, CA--(Marketwire - September 26, 2007 ) - Emergent Success Inc. today announced the launch of ES-Extranet a proprietary web-based collaboration tool for use by their clients, partners and consultants. Since the email "inbox" was not designed as a collaborative work environment, this technological solution creates the open space where discussion, calendaring, asset sharing and other collaborative activities are easily practiced and navigated.

Emergent Success, Inc. is a collaborative consulting company that facilitates dialogues to assist clients in solving their real-time problems. Even though the preference is to do this work in vivo, the addition of the ES-Extranet will allow anyone involved in a current collaboration to participate in an asynchronous manner. The principals at Emergent Success believe that in the same way that there is enormous value in gathering people together for in-person dialogues, there is also significant value to "virtual" dialogues. Principal Kevin Buck explains "Experience has shown that to engage people with an online tool once you have engaged them in person maximizes any collective effort -- it is not an either/or, but a both/and."

With an eye to collaborative integrity, Emergent Success engaged with David Muro, designer, and Jules Gravinese, web developer, to co-create this new tool. Each brought the best of their knowledge and experience to bear as they developed the intuitive feel and ease of use of this online workspace. Since collaborations are an iterative process, we look forward to the ongoing learning for our company, consultants and clients.

About Emergent Success, Inc.

Emergent Success assists clients to solve their real-time issues by liberating the collective wisdom, talent and energy from within their organization for the emergence of strategic success. Its senior consultants facilitate collaborative dialogues that create systemic integration amongst the unintended silos present in most organizations. The Company is headquartered in Mountain View, CA with consultants located across the United States. www.emergentsuccess.com

Pagination with ColdFusion and MySQL

I find that web development with MySQL to be so much more pleasurable than with MS SQL Server. Here is a great example to prove my point. In another post I showed how to pull off pagination with MS SQL and ColdFusion. Lots of SQL code. And it required running the query twice. Once to count the entire result set, and another time for the results to display.
This version however, is very slim. It makes use of MySQL's SQL_CALC_FOUND_ROWS, FOUND_ROWS(), and LIMIT.

SQL_CALC_FOUND_ROWS(): SQL_CALC_FOUND_ROWS and FOUND_ROWS() can be useful in situations when you want to restrict the number of rows that a query returns, but also determine the number of rows in the full result set without running the query again. An example is a Web script that presents a paged display containing links to the pages that show other sections of a search result. Using FOUND_ROWS() allows you to determine how many other pages are needed for the rest of the result.

FOUND_ROWS(): A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include a SQL_CALC_FOUND_ROWS option in the SELECTFOUND_ROWS() afterward.

LIMIT: The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments. With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return.

So let's go take a look at this beauty...

» Continue Reading »

WebVeteran.com based code deployed on Apple Inc.'s website

Wow how cool is this?

Scriptaculous' modified version of my JS Audio Engine is being used by Apple!
EX: http://www.apple.com/aperture/

» Continue Reading »

Control iTunes from a DragThing dock

While working, I use iTunes. But I find that the controller gets obscured by other windows. Or it just plain clutters my desktop. So I wanted to get  rid of the controller but still use iTunes.

There are many utilities that will control iTunes. But I didn't want to load another program on my development machine. However I do run DragThing on my system. I consider it as part of the OS.

If you have an iTunes icon in a dock, you can right click to show the menu and control iTunes right from there. But I didn't like the extra step. So I came up with another solution.

Using three AppleScripts, I made it so you can controll iTunes from within a dock without any menus. All you have to do is expand the draw and click play (or next/previous). Check out the movie:


Full Size Movie : 705x312 | 2.5MB

I left the iTunes conteler up to demonstrate the functions of the buttons in DragThing. Being that everything works, you can close the iTunes controller - which does not quit iTunes or interrupt the music in any way. You're left with a clean desktop, and quick access to iTunes from a DragThing dock. Sweet.

How To...

» Continue Reading »

Referer Cloud

Using ColdFusion I look for the referring web page that sent a viewer to my site. Then I split that traffic up into two categories: 1) Searches 2) Links. If a similar search term was seen before, I incriment it's weight. Same goes for domains of links. The result is a Referer cloud, very similar in look to a Tag Cloud:

Referer Cloud
But I find this MUCH more interested than a tag cloud...

» Continue Reading »

Scriptaculous audio engine - based on WebVeteran.com code

The forthcoming Scriptaculous (version 1.71?) may have an audio engine. The base of which is from yours truly.
For WebVeteran.com I had built a JavaScript audio engine:

  • Start a sound at any time
  • Stop that sound any time thereafter
  • Start another sound while the previous sound(s) are playing

The result is a multi-track audio engine that is accessed through JavaScript. It uses Scriptaculous' Builder to create and kill sounds.

Being so excited of my accomplishment, I wrote an email to Thomas Fuchs, creator of Scriptaculous, telling him of what I did. He asked if he can incorporate my work into the next release, as audio.js, along side effects.js, dragdrop.js, etc. Of course I said yes.

» Continue Reading »

Pagination with ColdFusion and MSSQL (faux MySQL's LIMIT X,Y)

Pagination is something that has always been somewhat difficult for me. Especially optimizing it for large sites. To make it even harder, the customer wants the first page to show three items, and every subsequent page to show ten. Not hard enough? OK, they want page number links instead of simple left/right arrow links, such as:

1 2 3 [4] Next »

Still Easy?

  • Only show 4 page links at a time
  • When you click 'next', show the next block of 4 pages
  • When you click 'prev', show the previous block of 4 pages
  • If you are on the first block of links, do not show the 'prev' link
  • If you run out of records, only show the correct number of page links in that block
  • If you run out of records, do not show the 'next' link

Remember, page 1 has 3 items. Page 2 has 10. So the math gets kinda tricky when you don't want to do 'what page are we on' statements all over the place.

Here is my solution. All you have to do is enter your records per page ("allperpage"), number of page links at a time ("blocksof"), and the number of items on the first page ("firstperpage").

The SQL query has been optimized to get as close to MySQL's 'LIMIT' function as possible. We're doing an INNER JOIN here, and sorting on columns from both tables. I haven't seen any examples of this optimization technique with an inner join, or even sorting on more than one column. We pull back the max rows we'd need, then trim the top with a reverse sort, finally un-reverse the sort for the web page. WHEW.

Onto the code...

» Continue Reading »

JavaScript: Round to any multiple of a specific number

The Javascript Math.Round() function is used for rounding to whole numbers, or decimals:

Math.round(25.9) //returns 26
Math.round(25.2) //returns 25
Math.round(-2.58) //returns -3
Math.round(28.453*100)/100 //returns 28.45

But what if you want to round to the nearest multiple of 7? Not a problem! The solution is easier than the question sounds...

» Continue Reading »

BlogCFC was created by Raymond Camden. This blog is running version 5.6.001.