Skip to content

Instantly share code, notes, and snippets.

View bixb0012's full-sized avatar

Joshua Bixby bixb0012

View GitHub Profile
@bixb0012
bixb0012 / arcpy_add_dataset_property_as_data_attribute.py
Last active July 31, 2019 18:18
ArcPy: Add Dataset Property as Data Attribute
#!python
# Reference: 1) https://pro.arcgis.com/en/pro-app/arcpy/functions/describe.htm
# 2) https://pro.arcgis.com/en/pro-app/tool-reference/data-management/add-field.htm
# 3) https://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field.htm
import arcpy
# Example 1: Adding path attribute for tables and feature classes in workspace (ArcMap and Pro compatible)
workspace = # Workspace containing feature classes
@bixb0012
bixb0012 / arcpy_describe_geodatabase_contents.py
Last active February 9, 2021 20:16
ArcPy: Describe Geodatabase Contents
#!python
# Reference: 1) https://pro.arcgis.com/en/pro-app/arcpy/data-access/walk.htm
# 2) https://pro.arcgis.com/en/pro-app/arcpy/functions/describe.htm
# 3) https://docs.python.org/3/library/os.path.html
import arcpy
import os
gdb = # Path to geodatabase
@bixb0012
bixb0012 / icon_sisyphean.svg
Created July 30, 2019 16:33
Icon: Sisyphean
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bixb0012
bixb0012 / powershell_regular_expressions.ps1
Last active April 2, 2021 20:37
PowerShell: Regular Expressions
#Requires -Version 5.1
# Reference: 1) https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_regular_expressions
# Reference: 2) https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference
$TestEmailFrom = @(
"smokey.bear@usda.gov"
" smokey.bear@usda.gov "
"<smokey.bear@usda.gov>"
" < smokey.bear@usda.gov > "
"Smokey Bear <smokey.bear@usda.gov>"
@bixb0012
bixb0012 / powershell_servicepointmanager_customizations.ps1
Last active April 26, 2021 21:56
PowerShell: ServicePointManager Customizations
#Requires -Version 5.1
# Reference: 1) https://docs.microsoft.com/en-us/dotnet/api/system.net.servicepointmanager
# Reference: 2) https://docs.microsoft.com/en-us/dotnet/api/system.net.security.remotecertificatevalidationcallback
# Example 1: Force TLS 1.2 connections from client
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Example 2: Ignore all SSL/TLS policy errors, e.g., ignore SSL/TLS secure channel errors
# from self-signed certificates
@bixb0012
bixb0012 / powershell_security.ps1
Last active April 30, 2021 19:58
PowerShell: Security-related
#Requires -Version 5.1
# Reference: 1) https://docs.microsoft.com/en-us/dotnet/api/system.security.principal
# Example 1: Retrieve security identifier value (SID) for an NT account
# Adapted from https://devblogs.microsoft.com/scripting/use-powershell-to-translate-a-users-sid-to-an-active-directory-account-name/
$DomainName = "" # Domain of account, commonly $Env:USERDOMAIN
$AccountName = "" # Name of account, commonly $Env:USERNAME
$NTAccount = [Security.Principal.NTAccount]::New($DomainName, $AccountName)
$Sid = ($NTAccount.Translate([Security.Principal.SecurityIdentifier])).Value
@bixb0012
bixb0012 / python_class_tree_helpers.py
Created February 23, 2022 21:39
Python: Class Tree Helpers
#!python3
# Reference: 1) https://docs.python.org/3/library/stdtypes.html#special-attributes
# Example 1: Function to print base class or subclass hierarchies
def print_classtree(cls, bases=True, level=0):
print(f"{'-'*2*level} {cls}")
if bases:
classes = cls.__bases__
else:
classes = cls.__subclasses__()
@bixb0012
bixb0012 / pyodbc_connect_database.py
Created August 30, 2016 16:43
PyODBC: Connect to Database
# Reference: 1) https://mkleehammer.github.io/pyodbc
# 2) https://docs.python.org/3/library/re.html#regular-expression-objects
import pyodbc
import re
driver_regexes = {
"mssql": ("ODBC Driver.*SQL Server", "SQL Server Native Client.*"),
"oracle": ("Oracle in.*")
}
@bixb0012
bixb0012 / powershell_management.ps1
Last active July 3, 2022 23:40
PowerShell: Management-related
#Requires -Version 5.1
# Reference: 1) https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist
# Reference: 2) https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch
# Reference: 3) https://docs.microsoft.com/en-us/dotnet/api/system.io.filestream
# Example 1: Copy file and measure combined (read & write) transfer rate over time
$FilePath = "" # Path of the file to copy
$Destination= "" # Path to the new directory or folder
$BufferSize = 64 # Buffer size, in KB, for copying file
@bixb0012
bixb0012 / arcpy_arcmap_modify_layer_symbology_expanded.py
Last active March 29, 2023 22:14
ArcPy (ArcMap): Modify Layer Symbology, Expanded
#!python2
# Example 1a adapted from https://www.reddit.com/r/gis/comments/4rhvhh/map_automation_arcpymapping_make_lyr/
#
# Reference: 1) http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm
# 2) https://docs.python.org/2/library/json.html
import arcpy
import json
lyr = # Layer object, typically from arcpy.mapping.ListLayers (arcpy._mapping.Layer)