Skip to content

Instantly share code, notes, and snippets.

@JeffJacobson
JeffJacobson / RouteExtensions.cs
Created March 29, 2012 20:39
WA State Route related extension methods for .NET
/*
* Jeff Jacobson, CGIS, ITS3
* 2008-09
*/
using System.Text.RegularExpressions;
using System;
namespace Wsdot.Cgis.Extensions
{
@JeffJacobson
JeffJacobson / LayerTypeDetector.cs
Created March 29, 2012 20:55
Detect ArcGIS REST API layer type
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web.Script.Serialization;
namespace LayerTypeDetector
{
class Program
@JeffJacobson
JeffJacobson / objectToHtmlList.js
Last active October 2, 2015 21:18
Convert object to HTML list
/**
* Writes the properties of an object to a definition list.
* @param Any type of object.
* @return {string} Returns a definition list for most objects. Returns an ordered list for Arrays. Strings and Dates will return a string.
*/
function objectToList(obj) {
var name, output, t, v;
t = typeof(obj);
@JeffJacobson
JeffJacobson / tocsv.js
Last active July 21, 2023 13:53
JavaScript object to CSV
/**
* Converts a value to a string appropriate for entry into a CSV table. E.g., a string value will be surrounded by quotes.
* @param {string|number|object} theValue
* @param {string} sDelimiter The string delimiter. Defaults to a double quote (") if omitted.
*/
function toCsvValue(theValue, sDelimiter) {
var t = typeof (theValue), output;
if (typeof (sDelimiter) === "undefined" || sDelimiter === null) {
sDelimiter = '"';
@JeffJacobson
JeffJacobson / ArcGIS Server 10.1 SOE output format bug workaround.cs
Last active October 8, 2015 17:08
ArcGIS Server 10.1 SOE output format bug workaround
/// <summary>
/// <para>ArcGIS Server 10.1 introduced a bug that causes the output format to always be set to "json"
/// even if another format (e.g., "xml") is specified via the "f" parameter in the HTTP request.
/// This method reads the "f" parameter from the <paramref name="operationInput"/> and sets the
/// <paramref name="outputFormat"/> to be the same value as the "f" parameter.</para>
/// <para>If there is no "f" parameter in <paramref name="operationInput"/> then
/// <paramref name="outputFormat"/> will retain its original value.</para>
/// </summary>
/// <param name="boundVariables"></param>
/// <param name="outputFormat"></param>
@JeffJacobson
JeffJacobson / generateAddressScoreCss.js
Created September 21, 2012 16:48
Generates CSS styles for address candidate scores.
function generateScoreColorCss() {
/// <summary>Generates CSS style element that colors address candidate scored elements add adds the element to &lt;head&gt;.</summary>
/// <returns type="jQuery">
var i, output = $("<style>"), css;
function generateStyle(min, max, color) {
var style = [];
for (i = min; i <= max; i++) {
if (i > min) { style.push(","); }
style.push(".score-" + i);
@JeffJacobson
JeffJacobson / splitCamelCase.js
Last active August 26, 2023 10:42
Splits camelCase or PascalCase words into individual words.
/**
* Splits a Pascal-Case word into individual words separated by spaces.
* @param {Object} word
* @returns {String}
*/
function splitPascalCase(word) {
var wordRe = /($[a-z])|[A-Z][^A-Z]+/g;
return word.match(wordRe).join(" ");
}
@JeffJacobson
JeffJacobson / WebMercatorGeographicConversion.cs
Created October 23, 2012 18:12
Functions to convert between web mercator and geographic coordinates.
// from http://www.gal-systems.com/2011/07/convert-coordinates-between-web.html
private void ToGeographic(ref double mercatorX_lon, ref double mercatorY_lat)
{
if (Math.Abs(mercatorX_lon) < 180 && Math.Abs(mercatorY_lat) < 90)
return;
if ((Math.Abs(mercatorX_lon) > 20037508.3427892) || (Math.Abs(mercatorY_lat) > 20037508.3427892))
return;
@JeffJacobson
JeffJacobson / Usgs.Elevation.cs
Created October 23, 2012 18:55
Consuming USGS Elevation Web Service
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.269
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
@JeffJacobson
JeffJacobson / WsdotTravelerApiProxy.ashx.cs
Last active December 10, 2015 06:08
Demonstrates how to detect a WSDOT Traveler API REST Request URL and append an access code from web.config. Designed for use with a Proxy page, as described at http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/ags_proxy.htm.
/// <summary>
/// Appends an AccessCode parameter to the input URI if it is a WSDOT Traveler Info REST API URI and does not already have an AccessCode parameter.
/// </summary>
/// <param name="uri">The URI passed to the proxy. Note that this string will be modified if an access code is determined to be necessary.</param>
/// <example>
/// <code><![CDATA[public void ProcessRequest (HttpContext context) {
/// HttpResponse response = context.Response;
/// // Get the URL requested by the client (take the entire querystring at once to handle the case of the URL itself containing querystring parameters)
/// string uri = context.Request.Url.Query.Substring(1);
/// AddTravelerApiAccessCodeIfNecessary(ref uri);