Skip to content

Instantly share code, notes, and snippets.

View adamjstewart's full-sized avatar

Adam J. Stewart adamjstewart

View GitHub Profile
@adamjstewart
adamjstewart / bash-functions.sh
Last active October 2, 2016 16:12
Bash function body delimiters
#!/usr/bin/env bash
# Bash function bodies can be delimited by curly braces,
# but they don't have to be. The following are all valid
# function body delimiters:
#
# arithmetic: ((expression))
# test: [[ expression ]]
# subshell: (list)
# group: { list }
@adamjstewart
adamjstewart / bash-booleans.sh
Last active July 30, 2016 14:10
Bash boolean examples
#!/usr/bin/env bash
# Various methods of using Booleans in Bash
# Credit for most of these techniques comes from:
# http://stackoverflow.com/questions/2953646/
###########################################################
# Using the builtin 'true' and 'false' commands
###########################################################
@adamjstewart
adamjstewart / cvs-login.exp
Last active July 30, 2016 13:26
Automate login to multiple CVS repositories
#!/usr/bin/env expect
# Automates CVS login to ocr, hwr, and rcr.
# Prompts user for password a single time.
# Turn off timeout
set timeout -1
# Ask user for password
stty -echo; # make sure password isn't echo'ed
@adamjstewart
adamjstewart / bash-paths.sh
Created October 2, 2016 17:15
Bash relative vs. absolute paths
#!/usr/bin/env bash
# There are many ways to get a path to a file or script.
# This script showcases several of them and their pitfalls.
# Credit for most of these techniques comes from:
# http://stackoverflow.com/questions/4774054/
abs_path='/usr/bin/bash'
rel_path='.'
@adamjstewart
adamjstewart / Makefile
Last active February 9, 2019 19:32
Makefile for building Graphviz graphs
SRC := $(wildcard *.dot *.gv)
CMD := dot
.PHONY: help Makefile
# Put it first so that "make" without argument is like "make help".
help:
@echo Usage:
@echo
@adamjstewart
adamjstewart / self-aware.sh
Created December 20, 2019 17:39
Primitive example of a self-aware program that passes the mirror test
#!/usr/bin/env bash
# Continuously kill processes
# Use Ctrl+C to exit
while true
do
read -p "kill " pid
if [[ "$pid" == $$ ]]
@adamjstewart
adamjstewart / landsat.py
Created May 5, 2022 21:35
Creating a Landsat intersection dataset with TorchGeo
from torch.utils.data import DataLoader
from torchgeo.datasets import CDL, Landsat7, Landsat8, stack_samples
from torchgeo.samplers import RandomGeoSampler
landsat7 = Landsat7(root="...")
landsat8 = Landsat8(root="...", bands=Landsat8.all_bands[1:-2])
landsat = landsat7 | landsat8
@adamjstewart
adamjstewart / cdl.py
Created May 5, 2022 21:39
Creating a CDL intersection dataset with TorchGeo
cdl = CDL(root="...", download=True, checksum=True)
dataset = landsat & cdl
@adamjstewart
adamjstewart / sampler.py
Created May 5, 2022 21:41
Creating a geospatial sampler with TorchGeo
sampler = RandomGeoSampler(dataset, size=256, length=10000)
dataloader = DataLoader(dataset, batch_size=128, sampler=sampler, collate_fn=stack_samples)
@adamjstewart
adamjstewart / train.py
Created May 5, 2022 21:42
Training a model with TorchGeo
for batch in dataloader:
image = batch["image"]
mask = batch["mask"]
# train a model, or make predictions using a pre-trained model