Skip to content

Instantly share code, notes, and snippets.

@maphew
maphew / make-home-page.py
Created September 14, 2021 23:35
Generate a blog-style index page written in markdown
"""Generate a blog-style index page written in markdown.
A header line with link to page, followed by a few lines of the story.
"""
import os
from pathlib import Path
import dateutil.parser
from inspect import getsourcefile
here = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
Driver: DIMAP/SPOT DIMAP
Files: DIM_SPOT6_MS_201308032015087_SEN_1.XML
IMG_SPOT6_MS_201308032015087_SEN_1_R1C1.TIF
IMG_SPOT6_MS_201308032015087_SEN_1_R1C2.TIF
IMG_SPOT6_MS_201308032015087_SEN_1_R1C3.TIF
IMG_SPOT6_MS_201308032015087_SEN_1_R1C4.TIF
IMG_SPOT6_MS_201308032015087_SEN_1_R2C1.TIF
IMG_SPOT6_MS_201308032015087_SEN_1_R2C2.TIF
IMG_SPOT6_MS_201308032015087_SEN_1_R2C3.TIF
IMG_SPOT6_MS_201308032015087_SEN_1_R2C4.TIF
@maphew
maphew / ImageRepo.py
Created June 24, 2021 19:47
Compress to Cloud Geotiff stub in ArcGIS Pro python toolbox (rename to *.pyt to get Pro to recognize it)
# -*- coding: utf-8 -*-
import arcpy
from osgeo import gdal
gdal.UseExceptions()
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
@maphew
maphew / h3-grid-from-poly-test-01.py
Created February 1, 2021 18:46
Figuring out how to generate an H3 hex grid from a given poly layer, in Qgis python processing environment.
# adapted from https://github.com/ThomasG77/30DayMapChallenge/blob/master/day4_hexagons/data/h3-processing.py
import os
from qgis.utils import iface
from qgis.core import (
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsFeature, QgsField, QgsFields,
QgsGeometry, QgsPointXY, QgsProject,
QgsProcessingFeedback, QgsMessageLog,
@maphew
maphew / make-yt-nts-index-html-table.py
Created November 13, 2020 05:29
Yukon NTS Index in various formats
'''Print Yukon NTS tile names as html table with links, arranged in same order as they appear in a map index.
2015-Aug-19, Matt.Wilkie@gov.yk.ca
License: X/MIT
'''
nts_txt_ordered = '''117C 117D
117B 117A
116NO 116P
116JK 116I 106L 106K
@maphew
maphew / outlook-taskboard-config.json
Created September 22, 2020 23:25
Outlook-taskboard config with To-Do flagged emails enabled and shown in BACKLOG lane
{
"BACKLOG_FOLDER": {
"ACTIVE": true,
"NAME": "",
"TITLE": "BACKLOG",
"SORT": "-priority,duedate,categoryNames,subject",
"RESTRICT": "",
"DISPLAY_PROPERTIES": {
"OWNER": false,
"PERCENT": false,
@maphew
maphew / History Tracer.xml
Last active July 11, 2020 08:23
WIP: management scripts for History Tracer plugin for Leo
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo: http://leoeditor.com/leo_toc.html -->
<leo_file xmlns:leo="http://leoeditor.com/namespaces/leo-python-editor/1.1" >
<leo_header file_format="2"/>
<vnodes>
<v t="mhw.20200710235109.1"><vh>History Tracer</vh>
<v t="mhw.20200308223025.1"><vh>@int history-tracer-port=8088</vh></v>
<v t="mhw.20200710235122.1"><vh>@button leo-ver-serv-start</vh></v>
<v t="mhw.20200710235134.1"><vh>@button leo-ver-serv-list</vh></v>
<v t="mhw.20200710235410.1"><vh>@button leo-ver-serv-stop</vh></v>
@maphew
maphew / console-log.md
Last active March 17, 2020 04:53
Leo scripts to manage History Tracer plugin daemon

An edited excerpt from the console which started Leo

don't forget to launch leo-ver-serv!!!
==== @int history-tracer-port=8088 ====
Looking for 'leo-ver-serv' processes...
   PID   Name                   Status    
  3815   leo-ver-serv           sleeping  
========================================

This is just after Leo startup.

@maphew
maphew / arcpy-overhead.py
Last active March 11, 2020 13:00
What is your "import arcpy" overhead?
'''Measure and report the time it takes to simply `import arcpy`
Part of https://community.esri.com/message/914048-re-what-is-your-import-arcpy-overhead?
'''
from timeit import default_timer as timer
start = timer()
from datetime import datetime, timedelta
from uuid import uuid4
eventid = datetime.now().strftime('%Y%m-%d%H-%M%S-') + str(uuid4())
@maphew
maphew / add-recent-branches-list.sh
Last active November 19, 2019 17:43
Git shallow clone: only branches with recent activity, as determined by Github
# from https://stackoverflow.com/questions/58702233/git-shallow-clone-only-branches-with-activity-last-x-months
export URL=https://github.com/leo-editor/leo-editor/branches/active
curl $URL > x.html
printf '\n-- Commands to add the remote branches to the fetch list:\n'
grep 'data-branch-name' x.html | sed -r 's/^.*data-branch-name="(.*?)"(.*$)/git remote set-branches --add origin \1/'
printf '\n-- Modification dates for these branches:\n'
grep 'time-ago' x.html | sed -r 's/^.*datetime="(....-..-..).*$/\1/'