Categories
Contact Doug!
Learn About Doug!
View Doug Boude's online resume
updated 11/18/2009

View Doug Boude's profile on LinkedIn
Link to me!

Follow Doug Boude on Twitter
Follow me!

Be Doug's friend on Facebook
Befriend me!
(I promise not to follow you home)
OO Lexicon
Chat with Doug!
Recent Entries
You may also be interested in...
Web Hosting

<< July, 2015 >>
SMTWTFS
1234
567891011
12131415161718
19202122232425
262728293031
Search Blog

Recent Comments
Re: Providing For Service Layer Objects in CFWheels (by david belanger at 3/15 2:47 PM)
Re: November 7th, 2012 - Day 1 of the Restoration of America's Greatness (by Claire at 3/15 11:28 AM)
Re: November 7th, 2012 - Day 1 of the Restoration of America's Greatness (by Ernesto at 3/14 1:19 AM)
Re: November 7th, 2012 - Day 1 of the Restoration of America's Greatness (by Frederick at 3/13 9:47 PM)
Re: My Top 20 Life Lessons for Boys and Young Men (by jeffrey scott berry at 9/16 2:42 PM)
Re: Equivalent of SQL "TOP X" in Oracle (by Mark Foster at 7/07 4:04 PM)
Re: SQL Forward Engineering with Visio 2003 Professional (by Thomas at 6/26 4:41 AM)
Re: One Shot Query to Recalculate Orderby Field - MySQL (by gary at 6/17 6:46 PM)
Re: DON'T GET SICK IN ARKANSAS! (by r. wood at 5/25 12:00 AM)
Re: SQL Forward Engineering with Visio 2003 Professional (by Andrew at 4/30 6:14 AM)
Re: Basic Ajax Select List Filter in PHP (by good at 2/04 5:26 AM)
Re: Family Law: The Weapon of Choice for Woman Scorned (by swalker at 2/03 2:15 AM)
Re: Approaches to Building Strings: The Imploding Array (by bantal silikon at 2/01 9:44 PM)
Re: Disappearing IE Popup Window During Save/Open Dialog (by AddisonDean at 1/15 9:59 AM)
Re: My Top 20 Life Lessons for Boys and Young Men (by Alex at 1/13 8:45 PM)
Re: Array Loop Modifications in CFSCRIPT (by Alex at 11/25 11:18 AM)
Re: Array Loop Modifications in CFSCRIPT (by Abram at 11/14 11:32 PM)
Re: Recursive Functions in ColdFusion (by Dwayne at 10/25 3:47 PM)
Re: Porting Coldfusion Code to Mura (by dh at 10/16 10:14 AM)
Re: Viewing Option Text (in IE7) that's Wider than the Select List (by Devil May Cry at 9/26 1:38 AM)
Archives
Photo Albums
Funnies (5)
Family (3)
RSS

Powered by
BlogCFM v1.11

16 January 2015
When External JS Files Need Relative Paths in .NET MVC

Okay, so this may NOT be the most elegant solution to the challenge, but it frickin works and relatively pain-free, so I'm tossing it out there for whoever else it may help.

THE SCENARIO

You're building a .NET MVC (5, in my case) app and you have an external JS file that contains paths to image icons. (Yeah, the case can be made to simply mod the JS to do class swapping on dom elements and reference the images in a CSS file, but that's not happening in this scenario). Like so:

var DIR = '/MyImagePath/';
nodes.push({ id: 1, label: 'Main', image: DIR + 'Network-Pipe-icon.png', shape: 'image' });
nodes.push({ id: 2, label: 'Office', image: DIR + 'Network-Pipe-icon.png', shape: 'image' });
nodes.push({ id: 3, label: 'Wireless', image: DIR + 'Network-Pipe-icon.png', shape: 'image' });
edges.push({ from: 1, to: 2, length: LENGTH_MAIN });

But, when you execute your app, you get console errors that give you 404 errors due to an incorrect URL being used as the image path!

THE SOLUTION

What you need is to capture the 'http://mysite.com/' portion of your app's URL, and prepend it to your image path so that you end up with 'http://mysite.com/MyImagePath/' as the value of the DIR variable in the code sample above. The trick I pieced together from googling and used to my happy success was to set a JS variable waaaaaay up high in the hierarchy, at the base layout file, like so: 



<script type="text/javascript">var siteroot = '@Html.Raw(Request.Url.GetLeftPart(UriPartial.Authority) + Url.Content("~"))'; </script>

 

Then, within any of your external JS files that NEED a complete path, just reference the globally available 'siteroot' var you created, as in:

var DIR = siteroot + '/MyImagePath/';
nodes.push({ id: 1, label: 'Main', image: DIR + 'Network-Pipe-icon.png', shape: 'image' });
nodes.push({ id: 2, label: 'Office', image: DIR + 'Network-Pipe-icon.png', shape: 'image' });
nodes.push({ id: 3, label: 'Wireless', image: DIR + 'Network-Pipe-icon.png', shape: 'image' });
edges.push({ from: 1, to: 2, length: LENGTH_MAIN });

And voila, no more errors.

You're welcome.

Posted by dougboude at 6:17 PM | PRINT THIS POST! | Link | 0 comments



30 December 2014
Manually Installing Nuget Packages in Visual Studio 2013

I’m working on a .NET project and decided that I’d use StructureMap as my IOC framework within an MVC5 app. So, I do what anyone would probably do, and open the Package Manager in VS2013 to retrieve the desired Nuget package. I wait and I wait and I wait…the cursor spins…no results are returned. So I go to the package manager console and attempt to retrieve and install it in a more manual way. It seems that either because I don’t have administrative rights on my machine (I know, don’t ask), or because I’m sitting on a fairly secure network, that the package manager is unable to do its duty and retrieve the StructureMap package.

Package Manager Fail

After fiddling with it for a while and doing a lot of Googling for clues, I finally figured out how to manually install the package and its dependencies. Since it was a fairly convoluted process, I thought I’d blog it in case it saves someone else some pain later.


In a nutshell, here’s what we need to do:

1. Manually grab the Nuget packages (*.NUPKG) from Nuget.org;
2. Create a new Package Source in the Package Manager;
3. Install the desired package(s)

 

Manually Retrieving NUPKG Files

Normally, the package manager will consume Nuget’s REST API in order to retrieve the desired packages. This can also be done manually in the browser, which in this case we want to do. So:


1. Find the package you need on Nuget.org (note the name and version, as well as dependencies);

Nuget Search

2. Navigate to the REST URL that points to that package

Consuming Nuget API

Nuget Package Downloaded

note: if you want a specific version, append the version number to the end of the URL followed by a slash. If you omit the version (which is what I did in my example), Nuget will provide you the latest version of the package.

At that point, the package will download to your default downloads folder. Repeat this step for any dependencies this package has.

Create a new Package Source in the Package Manager

1. Open your Package Manager by right clicking the ‘References’ object in your object explorer and choosing ‘Manage Nuget packages’

Manage Nuget Packages in VS


2. Click the ‘Settings’ button

Package Manager Settings

3. Click the plus to add a new Package Source, (the name doesn’t matter), then browse to the location of the NUPKG files you downloaded and click Okay.

New Package Manager Source

4. You should now see the source you created listed, and all of the NUPKG files you downloaded available for installation!

Nuget Packages Available for Installation

5. Install the packages, any dependencies first and then your target package last. If you get errors telling you that some dependency isn’t fulfilled, you may need to install things in a different order, or you may have to go back to Nuget and retrieve more dependent packages. In my case, however, I was able to successfully install StructureMap for MVC5.

Posted by dougboude at 10:52 PM | PRINT THIS POST! | Link | 0 comments
05 December 2013
One Shot Query to Recalculate Orderby Field - MySQL

In my app, a 'listing' can have one or more photos associated with it. These photo records live in their own table...listingImages. I allow the user to decide in what order the photos should be displayed, so I have a field in the table called 'imageOrder' that stores a number to sort by when outputting. When a user edits a listing and decides to delete one or more photos, I need to update the table's 'imageOrder' field for the remaining photos. Now, if I did NOT do this, the images would still be sorted in the correct order (I think), but I would much prefer to have an imageOrder value list that begins with 1.

SO...how best to accomplish this. There are a hundred ways to do anything, and I probably considered at least three or four of them before settling on one that involved the execution of a single query. Here it is, in all its glory and for your (and my) future reference:

 

UPDATE listingimages i
inner join (
 SELECT  l.imageid,   
         @curRow := @curRow + 1 AS row_number
 FROM    listingimages l
 JOIN    (SELECT @curRow := 0) r
 WHERE   l.listingID = 5
 order by l.imageorder
) l on i.imageid = l.imageid
SET i.imageorder = l.row_number

Works like a champ! Note that in my subquery, I'm including an 'order by' that sorts the existing records by their current imageorder value. This is necessary so that the first image (whether it's current imageorder value was 3 or 300) ends up with a value of 1, the second record gets a value of 2, etc.

This particular solution is specific to MySQL, but I'm certain there are equivalent versions of this for any other flavor of DB as well.

Hope this helps someone!

Posted by dougboude at 5:08 PM | PRINT THIS POST! | Link | 1 comment