Skip to content

Instantly share code, notes, and snippets.

View alexgleith's full-sized avatar

Alex Leith alexgleith

View GitHub Profile
@rdp-cloud
rdp-cloud / awscli-currentAmzLinux.sh
Created March 31, 2017 22:01
When run from an EC2 instance this snippet will return the CURRENT ami id for Amazon Linux in the REGION that the instance is running in and load it up into a variable called currentAMI.
#!/bin/bash -xe
# grab the Availability Zone from the Meta Data service
az=$(curl http://169.254.169.254/latest/meta-data/placement/availability-zone/)
# drop the trailing zone to get the REGION the instance is running in.
currentRegion=${az%?}
# retirve the source AMI (latest Amazon Linux image in this case)
currentAMI=$(aws ec2 describe-images --owners self amazon --filters "Name=name,Values=amzn-ami-hvm-*gp2" --query 'Images[].[CreationDate,ImageId]' --output text --region $currentRegion | sort -k1 | tail -n1 | awk '{print $2}')
@bmcbride
bmcbride / postgis_geojson.php
Created February 26, 2012 05:43
PHP PostGIS to GeoJSON
<?php
/**
* PostGIS to GeoJSON
* Query a PostGIS table or view and return the results in GeoJSON format, suitable for use in OpenLayers, Leaflet, etc.
*
* @param string $geotable The PostGIS layer name *REQUIRED*
* @param string $geomfield The PostGIS geometry field *REQUIRED*
* @param string $srid The SRID of the returned GeoJSON *OPTIONAL (If omitted, EPSG: 4326 will be used)*
* @param string $fields Fields to be returned *OPTIONAL (If omitted, all fields will be returned)* NOTE- Uppercase field names should be wrapped in double quotes
* @param string $parameters SQL WHERE clause parameters *OPTIONAL*