Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tjmichael81's full-sized avatar

Timothy Michael tjmichael81

View GitHub Profile
-- Create table for PGH 311 requests
create table if not exists pgh_311_requests (
REQUEST_ID integer,
CREATED_ON varchar,
REQUEST_TYPE varchar,
REQUEST_ORIGIN varchar,
STATUS integer,
DEPARTMENT varchar,
NEIGHBORHOOD varchar,
COUNCIL_DISTRICT integer,
@tjmichael81
tjmichael81 / QBServiceChecker.ps1
Last active October 26, 2018 12:46
Basic PowerShell script to check the status of a Windows service, and start the service if the status is 'Stopped'
#requires -version 2
<#
.SYNOPSIS
PowerShell script to check the status of a Windows service, and start the service if status is 'Stopped'
.DESCRIPTION
PowerShell script to check the status of a Windows service, and start the service if status is 'Stopped'
.PARAMETER <Parameter_Name>
None
@tjmichael81
tjmichael81 / dates.sql
Created October 12, 2018 14:53
SQL Date Selections
/** Get date and time stamp for today/now: **/
SELECT GETDATE()
/** Get today's date: **/
SELECT CONVERT(date, GETDATE())
/** Select records with today's date **/
/** Example below using an Esri versioned view **/
SELECT [OBJECTID]
,[DYETESTNUMBER]
@tjmichael81
tjmichael81 / esri_python.py
Last active March 27, 2018 19:35
Esri Python API Samples
#-------------------------------------------------------------
# Boilerplate connection / authentication
#-------------------------------------------------------------
import arcgis
from arcgis.gis import GIS
# Login credentials
url = "<url to agol or portal>"
username = "<user name>"
password = "<password>"
@tjmichael81
tjmichael81 / description.html
Created August 9, 2017 19:30
ArcGIS Online - Organization Description Tweaks
<style>
/**
Move the position of the Featured Maps container. With a banner image that is 472px high, a 25px margin will move the container toward the bottom of the image.
A 100px margin will add additional area below the banner image.
**/
#featuredMaps {
margin-top: 25px;
}
/**
@tjmichael81
tjmichael81 / Delete ami and snapshots.ps1
Last active October 2, 2022 19:21
Use a date search to find and delete AWS AMI's and their corresponding disk snapshots
<#
### Resources: ###
# How-To Delete Unutilized EBS-Based AMIs And Corresponding Snapshots
# http://www.n2ws.com/how-to-guides/how-to-delete-unutilized-ebs-based-amis-and-corresponding-snapshots.html
# Deleting Snapshots by Using the AWS Tools for Windows PowerShell
# http://docs.aws.amazon.com/storagegateway/latest/userguide/DeletingSnapshotsUsingPowerShell.html
# Adding and Removing Items from a PowerShell Array
@tjmichael81
tjmichael81 / calcFieldWithDict.py
Created February 11, 2016 17:44
Calculate fields using arcpy.da.UpdateCursor and a dictionary containing values for new fields
import arcpy
gridID_dict = {1:'A1', 2:'A2', 3:'A3', 4:'A4',
5:'B1', 6:'B2', 7:'B3', 8:'B4',
9:'C1', 10:'C2', 11:'C3', 12:'C4',
13:'D1', 14:'D2', 15:'D3', 16:'D4'}
fc = r'<path to file>'
# Fields will need to be updated with fields from source
fields = ['OID@', 'br2PolyID', 'ID']
@tjmichael81
tjmichael81 / calculateFieldExampleWithSeparator.py
Created January 4, 2016 14:55
Use arcpy.CalculateField_management to concatenate two fields with a separator
import arcpy
fc = '<path to fc or table>'
field_CommonName = 'Field_CommonName'
field_BotanicalName = 'Field_BotanicalName'
# Takeaway - enclose the entire expression in quotes, don't do this:
# commonNameExpression = !Field_Name! + ' - ' + !Current_Crop_2013!
commonNameExpression = "!Field_Name! + ' - ' + !Current_Crop_2013!"
@tjmichael81
tjmichael81 / aws_createsnapshots.ps1
Last active October 16, 2015 01:54
Create snapshots for each volume attached to an instance
# Retrieve instance ID from EC2 Instance Metadata
$instanceID = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id")
# Retrieve volumes that are attached to this instance
$volumes = Get-EC2Volume -Filter @{Name = "attachment.instance-id"; Value = $instanceID}
# Create a snapshot for each volume in the collection
foreach ($volume in $volumes){
$volID = $volume.VolumeId
$diskSnapshot = New-EC2Snapshot -VolumeId $volume.VolumeId -Description "Snapshot of $volID from $instanceID"
@tjmichael81
tjmichael81 / Esri feature row count.py
Last active October 13, 2016 19:30
Use ArcPy to create a text file with datasets, feature classes, and row counts
import arcpy
arcpy.env.workspace = r"C:\TEMP\LocalGovernment.gdb"
outFile = open(r"C:\TEMP\dbinventory.txt", "a")
dsList = arcpy.ListDatasets(feature_type="feature")
for ds in dsList:
outFile.write("Dataset: {0}{1}".format(ds, "\n"))
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):