Skip to content

Instantly share code, notes, and snippets.

View mdiener21's full-sized avatar

Michael Diener mdiener21

View GitHub Profile
@mdiener21
mdiener21 / round_minutes_to_quarter_hour.py
Last active April 4, 2024 09:05
Python round minutes to the nearest quarter hour
def round_to_nearest_quarter_hour(minutes, base=15):
"""
Input: A value in minutes.
Return: An integer rounded to the nearest quarter-hour (0, 15, 30, 45) based on the base interval,
with special handling to ensure rounding from 0 up to 7 goes to 0 and 8 to 15 round to 15
Example round_to_nearest_quarter_hour(0) rounds to 0
round_to_nearest_quarter_hour(7) rounds to 0
round_to_nearest_quarter_hour(8) rounds to 15
round_to_nearest_quarter_hour(22) rounds to 15
@mdiener21
mdiener21 / test-data.geojson
Created November 29, 2018 14:51
test project data
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mdiener21
mdiener21 / select_polys_inside.sql
Created November 9, 2018 20:21
Postgis select polygons that are inside and not touching
SELECT c.cadaster_id, r.name
, CASE
WHEN ST_CoveredBy(c.geom, r.geom)
THEN c.geom
ELSE
ST_Multi(
ST_Intersection(c.geom,r.geom)
) END AS geom
FROM cadaster AS c
INNER JOIN roads_ply AS r
@mdiener21
mdiener21 / buffer_with_dissolve.sql
Created October 30, 2018 09:43
PostGIS buffer and dissolve polygons based on IDs.
-- create a 0.5m buffer with square edges using mitre join
-- used for buffering building spaces to create a floor space
-- only taking 5 ids
SELECT fk_building_id, fk_building_floor_id,
st_multi(ST_Union(St_Buffer(b.geom,0.5,'endcap=square join=mitre mitre_limit=2')))
AS geom FROM django.buildings_buildingfloorspace AS b
WHERE floor_num = 1 AND fk_building_id IN (2,3,6,7,8)
GROUP BY fk_building_id, fk_building_floor_id
@mdiener21
mdiener21 / geoserver-cors.xml
Created October 22, 2018 06:47
Geoserver Cors settings for Tomcat
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
@mdiener21
mdiener21 / openlayers_stacked_style.js
Last active October 3, 2018 14:41
Openlayers stacked font awesome styles for points
// using font awesome 5 free version
var faFlagSolidStyle = new ol.style.Style({
text: new ol.style.Text({
text: '\uf024', // fas flag solid
scale: 1,
font: 'normal 18px FontAwesome',
offsety: -30,
offsetx: -10,
fill: new ol.style.Fill({color: 'black'}),
})
@mdiener21
mdiener21 / dikstra_graph.py
Created July 13, 2018 06:00
Python Dijkstra
# source: https://dev.to/mariamxl
# https://dev.to/mariamxl/dijkstras-algorithm-in-python-algorithms-for-beginners-dkc
from collections import deque, namedtuple
# we'll use infinity as a default distance to nodes.
inf = float('inf')
Edge = namedtuple('Edge', 'start, end, cost')
@mdiener21
mdiener21 / install-qgis3-ubuntu1604.sh
Last active July 12, 2018 12:56
Install QGIS 3 on Ubuntu 16.04
--QGIS 3 Ubuntu 16.04
sudo sh -c 'echo "deb https://qgis.org/ubuntugis xenial main" >> /etc/apt/sources.list'
sudo sh -c 'echo "deb-src https://qgis.org/ubuntugis xenial main" >> /etc/apt/sources.list'
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
wget -O - https://qgis.org/downloads/qgis-2017.gpg.key | gpg --import
gpg --fingerprint CAEB3DC3BDF7FB45
gpg --export --armor CAEB3DC3BDF7FB45 | sudo apt-key add -
@mdiener21
mdiener21 / bbox.py
Last active May 8, 2018 07:31
Find the center of a set of points using this bounding box class in python
class BoundingBox(coordinate_list):
"""
Return a 2D bounding box from a set of points
Example input: mypoints = [(0,2),(3,4),(5,6)]
Example Usage: BoundingBox(mypoints)
Example Usage: bbox = BoundingBox(mypoints)
bbox.width
bbox.height
bbox.centroid
"""
@mdiener21
mdiener21 / move_files.py
Last active April 17, 2018 07:48
Python move files within folders recursively into a new single folder
import os
from os.path import isfile, join
import shutil
my_path = "/home/username/Pictures"
file_types = ('.JPG', '.jpg', '.AVI')
year = '2010'
destination_folder = "/home/username/Pictures/final_2010"
for root, dirs, files in os.walk(my_path):