Skip to content

Instantly share code, notes, and snippets.

View neilkennedy's full-sized avatar

Neil Kennedy neilkennedy

View GitHub Profile
<script asp-src-include="/dist/myapp.*.js"></script>
{
output: {
filename: 'myapp.local.js'
}
}
<script src="@Html.Raw(Html.GetScripts("myapp.*.js"))"></script>
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
namespace MyApp.Helpers.HtmlHelpers
{
public static class HtmlHelperExtensions
{
private const string ScriptFolder = "dist";
{
output: {
filename: 'myapp.[contenthash].js'
}
}
@neilkennedy
neilkennedy / JavaScriptRegex.js
Created August 21, 2014 10:08
Some JavaScript regex's to keep handy
.replace(/\s{2,}/g, ' ')//remove all double spaces with a single
.replace(/[ \t\r]/g, ''),//remove all whitespace
.trim()//remove leading and trailing spaces (supported IE9+)
"POINT (-0.159689 51.463423)".match(/(-?\d+(\.\d+)?)/g);//return the latitude & longitude from this WKT string
@neilkennedy
neilkennedy / polyFromBounds.js
Last active April 10, 2021 10:39
Create a polygon from a Leaflet.js LatLngBounds object
/// <summary>
/// Takes an L.latLngBounds object and returns an 8 point L.polygon.
/// L.rectangle takes an L.latLngBounds object in its constructor but this only creates a polygon with 4 points.
/// This becomes an issue when you try and do spatial queries in SQL Server or another database because when the 4 point polygon is applied
/// to the curvature of the earth it loses it's "rectangular-ness".
/// The 8 point polygon returned from this method will keep it's shape a lot more.
/// </summary>
/// <param name="map">L.map object</param>
/// <returns type="">L.Polygon with 8 points starting in the bottom left and finishing in the center left</returns>
function createPolygonFromBounds(latLngBounds) {
@neilkennedy
neilkennedy / buffer.js
Created January 10, 2014 10:21
Use JSTS buffer function with Leaflet.js by exporting / importing GeoJSON
function buffer(leafletGeometry, distance){
var reader, input, buffer, bufferGeoJSON;
reader = new jsts.io.GeoJSONReader();
input = reader.read(leafletGeometry.toGeoJSON());
buffer = input.geometry.buffer(distance);
bufferGeoJSON = new jsts.io.GeoJSONWriter().write(buffer);
return L.geoJson(bufferGeoJSON);
@neilkennedy
neilkennedy / countries.js
Created September 3, 2013 13:07
GeoJSON Polygons of world countries. Easy to use in OpenLayers Raw coordinates originally found at http://mbostock.github.io/protovis/ex/countries.js
/*
* Coordinates found at Web Address : http://mbostock.github.io/protovis/ex/countries.js
* Original link Found : http://stackoverflow.com/a/6325428/814290
* Converted to GeoJSON here so we don't have to manipulate the data for OpenLayers.
*
* Can use linq.js (http://linqjs.codeplex.com/) to query.
* var country = $.Enumerable.From(countries).Where("x => x.code == 'IE'").FirstOrDefault();
*/
var countries = [{
@neilkennedy
neilkennedy / Lat_Long_Circle
Last active December 19, 2015 22:39
The "description" function returns a latitude & longitude value a certain amount of kilometers away from another latitude longitude point. This code was adapted from some Java code I found at http://forum.processing.org/topic/calculating-lat-and-long-from-bearing-and-distance The "circle" function uses the "distance" function to return an array …
function circle (curLon, curLat, distanceKm) {
var i = 0;
var circle = [];
while (i < 360) {
circle.push(this.destination(curLon,curLat, i, distanceKm));
i += 20;
}
return circle;
}