Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Bartsch pdbartsch

View GitHub Profile
@pdbartsch
pdbartsch / 8266_adafruitio_00_publish.ino
Created Mar 16, 2021
lightly modified example sketch to write to feed within group on Adafruit.io
View 8266_adafruitio_00_publish.ino
// Adafruit IO Publish Example
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
//
@pdbartsch
pdbartsch / arcmap_example_update_source_folder.py
Last active Mar 15, 2019
Simple example of updating a single mxd file that has missing sources when data is moved to a new folder. For more information see: http://desktop.arcgis.com/en/arcmap/10.6/analyze/arcpy-mapping/updatingandfixingdatasources.htm
View arcmap_example_update_source_folder.py
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Projects\arc_examples\broken_sources_example.mxd")
original_directory = r"C:\Projects\arc_examples"
new_directory = r"C:\Projects\arc_examples\data_moved_to_this_folder"
mxd.findAndReplaceWorkspacePaths(original_directory, new_directory)
mxd.saveACopy(r"C:\Projects\arc_examples\data_moved_to_this_folder\new_map.mxd")
del mxd
View fieldcalc04.py
# expression:
lat_main(!size!)
# code block:
def lat_main(diameter):
if (diameter >= 8):
return "Main"
else:
return "Lateral"
@pdbartsch
pdbartsch / dd_pages_export.py
Created Mar 6, 2019
ArcGIS Data driven pages export to Google Drive file sync
View dd_pages_export.py
# Name: dd_pages_export.py - Data Driven Page(s) to PDF
# Description: exports either a single data Driven Page or all pages from a .mxd document to pdf(s). Replaces multiple previous scripts in favor of user input.
# Author: Paul Bartsch - updated December 2018
# Intent: for use at UCSB to keep hosted PDF atlas sheets up to date with GIS data and ArcGIS Online Services (see other documents for help keeping online services in sync.)
# Python 2 because this one is intended for use with ArcGIS Desktop maps that have not yet been imported to ArcGIS Pro
## IMPORTS
import arcpy
## CONSTANTS
View fieldcalc03.py
# expression:
sqft_to_acres(!Shape_Area!)
# code block:
def sqft_to_acres(area):
return round((area / 43560),2)
View fieldcalc02.py
# expression:
abbreviate(!SciName!)
# code block:
def abbreviate(x):
words = x.split()
letters = [word[:2] for word in words]
return "".join(letters)
View fieldcalc01.py
# find the minimum value across a list of fields:
# expression:
min([!field1!, !field2!, !field3!])
# find the maximum value across a list of fields:
# expression:
max([!field1!, !field2!, !field3!])
# find the sum of all values from a list of fields:
# expression:
@pdbartsch
pdbartsch / cloudSettings
Last active Apr 12, 2021
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2021-04-12T19:47:25.457Z","extensionVersion":"v3.4.3"}
@pdbartsch
pdbartsch / cloudSettings
Created Feb 15, 2019
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2019-02-15T22:27:39.880Z","extensionVersion":"v3.2.5"}
View 12-list-ends.py
'''
Write a program that takes a list of numbers (for example, a = [5, 10, 15, 20, 25]) and makes a
new list of only the first and last elements of the given list.
'''
import random
a = random.sample(range(1, 100), 15)
def listends(a):
print('',a,'\n',[a for a in [a[0], a[-1]]])