Skip to content

Instantly share code, notes, and snippets.

@lydonchandra
lydonchandra / serializeXmlToString.js
Created May 8, 2012 03:22
Serialize XML to String for IE, Firefox, Chrome
// from https://gist.github.com/raw/554178/601c25f8ed6e84715dc36804efad915b4a62956d/XMLSerializer.js
var xmlString = '';
try {
// this works for Firefox, Chrome, Safari
xmlString = new XMLSerializer().serializeToString( clickResult );
} catch (e) {
// this works for IE6+
xmlString = clickResult.xml;
}
alert(xmlString);
@lydonchandra
lydonchandra / searchreplacenewline with backslash and newline
Created June 21, 2012 01:59
WebStorm Search and Replace newline with backslash and newline
WebStorm Search and Replace newline with backslash and newline
Text to find: \n
Replace with: \\\\\n
Regex on.
Results:
var xml = '<node1>\
<node2></node2>\
</node1>';
// HTTPS in ExpressJS 3.0
// Exec these 3 lines to generate your PEM files (Linux, OSX with OpenSSL installed)
//> openssl genrsa -out privatekey.pem 1024
//> openssl req -new -key privatekey.pem -out certrequest.csr
//> openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem
//Express app.js, HTTPS on port 3443
/**
@lydonchandra
lydonchandra / gist:3987712
Created October 31, 2012 15:34
apt-get install package=version
Before you install a specific version of a package you need it's complete version.
This will be displayed when you run:
apt-cache showpkg <package name>
e.g.
apt-cache showpkg subversion-tools
> Package: subversion-tools
> Versions:
> 1.3.2-5~bpo1(/var/lib/dpkg/status)
@lydonchandra
lydonchandra / gist:4050998
Created November 10, 2012 12:55
postgreSQL important folders
/etc/postgresql/9.1/main/
/var/lib/postgresql/9.1/main
/usr/share/postgresql/9.1/contrib/postgis-2.1/ (postgis.sql)
@lydonchandra
lydonchandra / gist:4063438
Created November 13, 2012 01:55
Iframe jquery access
// Find myForm in myIframe
var $myForm = $('#myIframe').contents().find('#myForm');
// set inputField value in $myForm
$('input[name="inputField"]', $myForm).val(JSON.stringify(inputField));
// check checkbox value in $printForm
$('input[name="myCheckbox"]', $myForm).val() === 'on'
// without jQuery
document.myForm.myCheckbox.checked
@lydonchandra
lydonchandra / gist:4230133
Created December 7, 2012 02:01
OpenLayers Delete Feature Control Using Box Selection(inherits from OpenLayers.Control.SelectFeature)
var olDeleteControl = new OpenLayers.Control.SelectFeature( layerToDrawOn, {
clickout: false, toggle: false,
multiple: true, hover: false,
toggleKey: "ctrlKey", // ctrl key removes from selection
multipleKey: "shiftKey", // shift key adds to selection
box: true
});
olDeleteControl.events.on({
'boxselectionend': function(layers){
@lydonchandra
lydonchandra / gist:4499081
Created January 10, 2013 03:04
Calculate Radius of a Circle in OpenLayers. Circle is implemented as a LinearRing.
OpenLayers.Geometry.LinearRing.prototype.getRadius = function() {
//http://gis.stackexchange.com/questions/20982/how-to-get-the-radius-of-a-circle-in-openlayers
//Use the formula for the area of a regular polygon.
//With a radius of r and k vertices (where in practice k typically varies from 4 through 360),
//the area now is A = r^2 * k Sin(360 / k) / 2. Solving for r yields r = Sqrt(2 A / (k Sin(360/k))).
//For k = 40 that's r = 0.565352 * Sqrt(A).
var area = Math.abs( this.getArea() );
var polygonSides = 100;
var radius = Math.sqrt( 2*area/(polygonSides*Math.sin(2*Math.PI/polygonSides)) );
return radius;
@lydonchandra
lydonchandra / gist:4728233
Last active December 12, 2015 06:19
getClosestResolutionIdx, Find the closest zoom level based on half of the difference of 2 resolution levels
/**
* Given a resolutionArray
* resolutionArr[0] = 100
* [1] = 50
* [2] = 25
* [3] = 12.5
*
* getClosestResolutionIdx(resolutionArray, 51) === 1 // round down to 50
* getClosestResolutionIdx(resolutionArray, 76) === 0 // round up to 100
* getClosestResolutionIdx(resolutionArray, 10) === 3 // round up to 3
@lydonchandra
lydonchandra / gist:5298647
Created April 3, 2013 05:26
Override OpenLayers Map.initialize()
var mapProto = OpenLayers.Map.prototype;
mapProto.initialize = function (div, options) {
//your map initialization code here
};
mapProto.CLASS_NAME = 'OpenLayers.Map_Custom';
OpenLayers.Map_Custom = OpenLayers.Class( mapProto );