Skip to content

Instantly share code, notes, and snippets.

@camwebb
camwebb / wrst.sql
Created September 20, 2024 20:26
SQL to find potential specimens in Wrangell-StElias NP, and format
SELECT
guid,
REGEXP_REPLACE(N.display_value, '[- ]+','') AS nps,
A.display_value AS alaac,
CONCAT_WS(', ', COL1L.attribute_value, COL1F.attribute_value) AS collector,
CASE
WHEN CN.display_value IS NOT NULL THEN CN.display_value
WHEN FN.display_value IS NOT NULL THEN FN.display_value
WHEN ID.display_value IS NOT NULL THEN ID.display_value
ELSE NULL END
@camwebb
camwebb / kuacnews2rss
Last active January 29, 2023 17:54
CGI script to generate an RSS feed for KUAC Morning News
#!/usr/bin/gawk -f
# kuacnews2rss
# Generates an RSS (XML) feed for the past week of KUAC Morning News
# Cam Webb <https://camwebb.info> 2023
# This code is Public Domain <https://unlicense.org/>
# Installation:
# 1. Shebang points to gawk
# 2. On Apache, add to .htaccess file:
@camwebb
camwebb / TCN_digi_query.sql
Last active February 9, 2022 02:37
Arctos SQL query for getting different stages of digitization at ALA, for N, Central and S Amercia
SELECT z.genus,
a.c AS N_all, b.c AS N_geo, c.c AS N_img, d.c AS N_tcn,
e.c AS C_all, f.c AS C_geo, g.c AS C_img, h.c AS C_tcn,
i.c AS S_all, j.c AS S_geo, k.c AS S_img, l.c AS S_tcn FROM
-- All genera
(SELECT DISTINCT genus FROM flat
WHERE guid_prefix = 'UAM:Herb') AS z
LEFT JOIN
@camwebb
camwebb / pdf2pdfa.sh
Created August 6, 2020 23:03
Converting a PDF (of an article) to PDF/A
IN=$1
OUT=$2
echo " ... cleaning annotations"
# https://gist.github.com/stefanschmidt/5248592
pdftk "$IN" output uncompressed.pdf uncompress
LANG=C sed -i -n '/^\/Annots/!p' uncompressed.pdf
pdftk uncompressed.pdf output final.pdf compress
@camwebb
camwebb / rothfels2012.ttl
Created June 25, 2020 21:49
RDF serialization of (small part of) paper discussed in <https://github.com/tdwg/tnc/issues/58
@prefix tc: <http://rs.tdwg.org/ontology/voc/TaxonConcept#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix : <http://alaskaflora.org/sw/rothfels2012.rdf#> .
# New property
:taxonConceptRelationshipAccordingTo
a owl:ObjectProperty ;
rdfs:comment """The property that relates the Taxon Concept Relationship
@prefix : <http://foo.com/bar#> .
@prefix dwc: <http://rs.tdwg.org/dwc/terms/> .
@prefix dwciri: <http://rs.tdwg.org/dwc/iri/> .
@prefix dsw: <http://purl.org/dsw/> .
@prefix tc: <http://rs.tdwg.org/ontology/voc/TaxonConcept#> .
@prefix tnu: <http://rs.tdwg.org/tnu/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix schema: <https://schema.org/> .
@prefix dc: <http://purl.org/dc/terms/> .
@camwebb
camwebb / cumulative_carbon_emissions
Last active October 18, 2019 23:50
Global cumulative carbon emissions (tonnes); three-quarters during my lifetime! (see comment for source and script)
year world_co2_emis cumulative prop
==== ============== ================= ====
1900 1,953,307,712 44,821,067,136 0.03
1901 2,017,969,984 46,839,037,120 0.03
1902 2,069,097,440 48,908,134,560 0.03
1903 2,257,269,488 51,165,404,048 0.03
1904 2,281,224,720 53,446,628,768 0.03
1905 2,428,667,744 55,875,296,512 0.04
1906 2,550,865,808 58,426,162,320 0.04
1907 2,884,659,872 61,310,822,192 0.04
@camwebb
camwebb / taxon_concept_example
Created October 2, 2019 18:52
Example taxon concept and taxon concept mapping data for Arctos
# publications
# ID|pub|url
1|Adams, J. F. H. 1817. Mém. Soc. Imp. Naturalistes Moscou 5: 94. |https://biodiversitylibrary.org/page/10128719
3|Meyer, C.A. 1829. Nouv. Mem. Soc. Naturalistes Moscou 1: 137.|https://biodiversitylibrary.org/page/33158044
5|Flora Rossica vol. 2, p 149|https://biodiversitylibrary.org/page/6104679
6||https://biodiversitylibrary.org/page/518966, Plate: https://biodiversitylibrary.org/page/519423
7|Syn. Fl. N. Amer. 1(1): 272. 1897|
8|Hulten E. 1939. Bot. Not. 1939: 826 (fig. 1).|https://journals.lub.lu.se/bn/article/view/11093/10504
9|Gombocz. 1940. BOTANIKAI KÖZLEMÉNYEK 37:9.|http://real-j.mtak.hu/8140/1/BotanikaiKozlemenyek_037.pdf
10|Flora of Alaska and Yukon|
@camwebb
camwebb / shared_is_function_of_sample.R
Created August 7, 2019 15:01
R script demonstrating reduced overlap between two communities with decreasing sample size
## Generate two large communities with:
## * 20% taxon overlap
## * Overlap of the more abundant species (Brown 1984, doi:10.1086/284267)
## * Identical uneven rank-abundance distributions
d <- matrix(c(rep(10,40), rep( 30,10), rep(100,10), rep( 0,40),
rep( 0,40), rep(100,10), rep( 30,10), rep(10,40)),
nrow=2, byrow=T)
colnames(d) <- paste("s", 1:100, sep="")
rownames(d) <- c("A", "B")
@camwebb
camwebb / smithsonian_coffee_job.md
Last active May 9, 2019 14:09
Job: “Shade Tree Species Catalog” for Indonesian coffee farmers

The Smithsonian Migratory Bird Center is seeking a Master’s- or PhD-level botanist or botany-focused ecologist to produce a “Shade Tree Species Catalog” for Indonesian coffee farmers and agronomists. Working in partnership with Conservation International and World Coffee Research (WCR), the catalog will accompany WCR’s widely-distributed Coffee Variety Catalogue https://varieties.worldcoffeeresearch.org/varieties, with the ultimate goal of promoting shade species planting alongside coffee farm planning and renovation. This 7 to 8-month research project will produce a growers’ field guide to Indonesian shade tree species, including their ecological, social and economic benefits to coffee