Skip to content

Instantly share code, notes, and snippets.

@jccartwright
jccartwright / list_html_dir.py
Created March 23, 2021 20:01
list files w/ specific extension in http directory
import requests
from bs4 import BeautifulSoup
def get_url_paths(url, ext='', params={}):
response = requests.get(url, params=params)
if response.ok:
response_text = response.text
else:
return response.raise_for_status()
soup = BeautifulSoup(response_text, 'html.parser')
@jccartwright
jccartwright / index.html
Created October 3, 2020 16:12
React-Leaflet v2 example
<div id="container"></div>
@jccartwright
jccartwright / gist:b65c231b1a499f90235ee27a1581ff5e
Created May 15, 2020 19:35
get a native OracleConnection from the SpringBoot-provided DataSource
assert dataSource != null
assert dataSource.getClass().name == 'org.apache.tomcat.jdbc.pool.DataSource'
assert dataSource.getConnection().getClass().name.startsWith('com.sun.proxy')
OracleConnection oracleConnection = dataSource.getConnection().unwrap(OracleConnection)
assert oracleConnection.getClass().name == 'oracle.jdbc.driver.T4CConnection'
NativeJdbcExtractor jdbcExtractor = new CommonsDbcpNativeJdbcExtractor()
OracleConnection con = jdbcExtractor.getNativeConnection(dataSource.getConnection())
assert con.getClass().name == 'oracle.jdbc.driver.T4CConnection'
@jccartwright
jccartwright / gist:d04b589e441884578bb6b4f134582984
Created January 15, 2020 18:11
Pie Chart using Google Charts API
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
// mock of data retrieved via the API
var rawDeviceData = [
{"name": "iPhone7,1", "valid": 303662, "total": 1090913},
{"name": "SM-G920V", "valid": 287159, "total": 1499170},
{"name": "LG-D850", "valid": 221267, "total": 1077458},
{"name": "iPhone8,2", "valid": 186012, "total": 649844}
@jccartwright
jccartwright / okeanos_observations_to_geojson.python
Last active September 26, 2019 20:48
convert Okeanos Explorer observations XML to GeoJSON
import xml.etree.ElementTree as ET
import json
def parse_xml(xmlfile):
features = []
output = {
"type": "FeatureCollection",
"features": features
@jccartwright
jccartwright / okeanos_observations_to_geojson.groovy
Last active September 26, 2019 20:48
convert Okeanos Explorer observations XML to GeoJSON
import groovy.json.*
def observationsUrl = 'url_for_xml_file'
xmlString = observationsUrl.toURL().text
// don't know why can't read URL directly
observations = new XmlSlurper().parseText(xmlString)
@jccartwright
jccartwright / csb_geojson2csv.groovy
Created May 30, 2019 19:11
read a gzipped GeoJSON file and write a CSV
import groovy.json.*
import groovy.io.FileType
import groovy.util.*
import java.util.zip.GZIPInputStream
def dataDir = new File("/data/csb_data")
assert dataDir.exists() && dataDir.isDirectory()
def outputDir = new File("/data/csb_data/csv")
assert outputDir.exists() && outputDir.isDirectory()
#!/usr/local/bin/bash
pid_file="/Users/jcc/pid_file"
command="ping -i 60 localhost"
###############################################################################
## user customization below this should not be required ##
###############################################################################
function start {
echo "starting..."
@jccartwright
jccartwright / gist:559fbdd3d8ad050fe11ca45b5568153d
Created May 24, 2019 15:27
bash script to stop/start/status a process. includes waiting for process to stop
#!/bin/bash
pid_file="/path/to/pidfile"
command="./t2.sh &"
function start {
echo "starting..."
$command
pid=$!
echo $pid > $pid_file
// sample JSON response
var jsonResponse = {"spatialReference":{"wkid":4326,"latestWkid":4326},"candidates":[{"address":"80305, Boulder, Colorado","location":{"x":-105.24280489999995,"y":39.983092300000067},"score":100,"attributes":{},"extent":{"xmin":-105.28580489999996,"ymin":39.940092300000067,"xmax":-105.19980489999995,"ymax":40.026092300000066}},{"address":"080305","location":{"x":70.684671556000069,"y":42.633023284000046},"score":100,"attributes":{},"extent":{"xmin":70.671671556000064,"ymin":42.620023284000048,"xmax":70.697671556000074,"ymax":42.646023284000044}},{"address":"80305","location":{"x":-107.45293038699998,"y":24.909200000000055},"score":100,"attributes":{},"extent":{"xmin":-107.88393038699998,"ymin":24.478200000000054,"xmax":-107.02193038699998,"ymax":25.340200000000056}},{"address":"080305","location":{"x":25.969188087000077,"y":43.900496861000079},"score":100,"attributes":{},"extent":{"xmin":25.968188087000076,"ymin":43.899496861000081,"xmax":25.970188087000079,"ymax":43.901496861000076}},