Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / waroute.js
Last active October 2, 2015 12:28
Regular expression that matches a WA state route ID
// This RegEx should match any valid state route identifier.
var _SR_REGEX = /^(\d{3})(?:((?:AR)|(?:C[DI])|(?:C[O])|(?:F[DI])|(?:LX)|(?:[PQRS][\dU])|(?:RL)|(?:SP)|(?:TB)|(?:TR)|(?:PR)|(?:F[ST])|(?:ML))([A-Z0-9]{0,6}))?$/i;
/*
==RRTs (Related Roadway Type)==
AR Alternate Route
CD Collector Distributor (Dec)
CI Collector Distributor (Inc)
CO Couplet
FI Frontage Road (Inc)
@JeffJacobson
JeffJacobson / ArcObjectsLinqExtensions.cs
Created March 6, 2012 22:32
Defines extension methods that allows LINQ to be used with ArcObjects "IEnum..." types.
using System;
using System.Collections.Generic;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Server;
namespace Wsdot.ArcObjects.Extensions
{
public static class ArcObjectsLinqExtensions
@JeffJacobson
JeffJacobson / SqlGeometryExtensions.cs
Created February 24, 2012 23:06
SqlGeometry <-> ESRI SOAP Geometry conversion extensions for .NET
namespace Wsdot.GIS.Geometry.Conversion
{
using System;
using System.Collections.Generic;
using ESRI.ArcGIS.SOAP;
using Microsoft.SqlServer.Types;
public static class SqlGeoemtryExtensions
{
/// <summary>