Friday, March 22, 2013

Calculating Distance with Google API and C#

Recently I had to use C# to calculate driving mileage between two locations.  Here's a great resource I found but they calculate in metric.

http://briancray.com/posts/calculate-driving-distance-google-maps-api

To convert the distance into miles, make the following modification at the end:


                miles = Math.Round((Double.Parse(distanceNode[0].ChildNodes[0].InnerText) / 1609.344d) * 100) / 100;

That's it! Very useful!

Tuesday, March 12, 2013

Canonical Tags

http://mikael.com/2013/01/seo-canonical-urls-in-sitecore/

If you need to set up canonical tags in sitecore, here's a real quick code snippet that lets you do it.  What are canonical tags?

Read this below:


In summar, canonical tags are used so that crawlers will know that your shortcut isn't copied content, it's just a shortcut.  That's it!

Thursday, February 28, 2013

Future Publishing Date

As I've been doing a lot of Sitecore work lately, I thought I'd begin recording my findings here.

My first Sitecore post is in regards to a question asked, "Is it possible to set a schedule a future publish in Sitecore?"

Here's the simple answer outlined in the article below:
http://blogs.perficient.com/portals/2012/03/09/scheduling-future-item-publishing-in-sitecore/

I thought the code snippet in there could prove to be useful.

*EDIT*
It turns out with Sitecore 6.5, automatic publishing can be set up with a config file.
http://reasoncodeexample.com/2012/03/12/sitecore-automatic-publishing/

Monday, February 11, 2013

Editing Javascript in Visual Studio

The other day I downloaded a javascript library to do some rss feeding. I quickly discovered that I need to add some additional functionality to said javascript, but when I opened the file I realized that like most javascript libraries, there are NO LINE BREAKS.  Of course, this is to minimize the size of the javascript file and supposedly it also provides a performance boost, but for my purposes it did nothing but keep me from being able to read the daggon' javascript.

Well, it turns out there's a quick way to automatically format the javascript in VS.  Just open up the file and go to Edit > Advanced > Format Document.  That's it!

Wednesday, May 23, 2012

Forcing an Identity ID into a SQL Table

If you're ever in a situation where you messed up and deleted a record, and you need to insert back in a record.. and the primary key has to be what you WANT it to be, and not what the auto-increment adds for you, here's how you do it:

 SET IDENTITY_INSERT ON
INSERT INTO ... 


 Very simple but handy little tool to know.

Monday, April 23, 2012

Word Wrap Css

Today I discovered a new css trick thanks to one of my coworkers at gvpi. I had a grid that would break whenever the string was way to long, for example, if the string said something like, "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", it would break the styles on the page because the content wouldn't fit nicely into the column I created.

Apparently now there's a trick with the newer browsers called word-wrap. Here's a link:
http://webdesignerwall.com/tutorials/word-wrap-force-text-to-wrap

Basically, it's just a css tag that looks like this: word-wrap:break-word;

Voila! That's it!

Friday, March 30, 2012

Broken Image?

Recently I found a really cool way to handle "broken images". This happens all the time when you have a some sort of auto-generated image, or an expected image but then sometimes the file doesn't exist, or something happened to it. Here is one fairly cheap way to set up a default image:

http://stackoverflow.com/questions/717734/best-way-to-display-default-image-if-specified-image-file-is-not-found


In other words, something like this:
<img src="image.jpg" onerror="this.onerror=null;this.src='default.jpg'">

So far I've tested in ie9, chrome, and firefox and works in all three. Pretty cool!