Skip to content

Instantly share code, notes, and snippets.

💭
🌒

Stephan Hügel urschrei

💭
🌒
Block or report user

Report or block urschrei

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View dump.py
#!/usr/bin/env python
# needs Pandas, Geopandas, Shapely. Should work on 2.7.x and 3.6.x
# this will only dump properties that are open or partially open today
# this can be adjusted by commenting out or altering the values given to isin()
from datetime import date
import geopandas as gp
import pandas as pd
from shapely.geometry import Point, LineString, Polygon, MultiPolygon, MultiPoint, box
@urschrei
urschrei / lib.rs
Last active Sep 25, 2018
Detect whether an (extended) ASCII string is a palindrome anagram using Rust
View lib.rs
// Given a string, how do you determine whether it's an anagram of a palindrome?
// Solution: Given the unique set of chars, at most 1 should appear in the string
// an odd number of times.
// chars() returns Unicode Scalar Values, and these might not match up
// with grapheme clusters, so this can't be assumed to work correctly
// for anything other than (extended) ASCII
fn unique_chars(s: &str) -> String {
let mut v: Vec<char> = s.chars().collect();
// dedup removes consecutive identical elements, so we need a sort first
View LSP_prefs.json
// Settings in here override those in "LSP/LSP.sublime-settings",
{
"clients":
{
"rls":
{
"auto_complete_triggers": [ {"selector": "source.rust", "characters": ".:"} ],
"diagnostics_highlight_style": "box",
"command": ["rustup", "run", "nightly", "rls"],
@urschrei
urschrei / minimum_polygon_distance.md
Last active May 23, 2019
An algorithm for determining the minimum distance between two non-convex polygons
View minimum_polygon_distance.md

Adapted from https://www.quora.com/How-do-you-compute-the-distance-between-two-non-convex-polygons-in-linear-time/answer/Tom-Dreyfus

Calculating the Minimum Distance Between Two Non-Convex Polygons

See Amato, Nancy M (1994) for details of the difference between separation (sigma: σ) and closest visible vertex (CVV).

Refer to P and Q as the two polygons with n and m vertices, respectively.
For the purposes of this discussion, a key insight is that it is enough to find the closest edge to each vertex in order to compute the minimum separation between P and Q.
This means iterating over all vertices, and finding a nearest neighbour. Thus, a time complexity in O((m + n) * log(m * n)) should be expected.

@urschrei
urschrei / png_to_polygon_to_geojson.py
Last active May 11, 2019
Read a PNG into a numpy array, convert it to a Shapely Polygon, and dump it as GeoJSON
View png_to_polygon_to_geojson.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created by Stephan Hügel on 2017-03-02
The MIT License (MIT)
Copyright (c) 2017 Stephan Hügel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
View dumpbin_cdylib.txt
Microsoft (R) COFF/PE Dumper Version 14.00.24215.1
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file target/release/lonlat_bng.dll
File Type: DLL
Section contains the following exports for lonlat_bng-f8cb032e62ae16ed.dll
@urschrei
urschrei / hexagram.py
Last active Nov 30, 2016
Generate and dump a hexagram in PNG format
View hexagram.py
# -*- coding: utf-8 -*-
# Requires PIL (pillow) and NumPy
# Copyright (C) Stephan Hügel, 2016
# License: MIT
import sys
from PIL import Image
import numpy as np
@urschrei
urschrei / playground.rs
Last active Feb 2, 2016 — forked from anonymous/playground.rs
Threaded send/receive using channels in Rust
View playground.rs
use std::thread;
use std::sync::mpsc::{ channel, Sender };
enum Wrapped {
A(f64),
B(f64),
}
fn produce_a(sender: Sender<Wrapped>) {
for i in 0 .. 5 {
@urschrei
urschrei / moved.md
Last active Aug 29, 2015
Comparing Mapzen's OSRM and Valhalla routing engine results for bicycle journeys in London
View moved.md
View gist:6b45fbc38d2b1d2f442b
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="verbose"
export GIT_PS1_SHOWDIRTYSTATE
export GIT_PS1_SHOWSTASHSTATE
export GIT_PS1_SHOWUNTRACKEDFILES
export GIT_PS1_SHOWUPSTREAM
PS1='\[\e[32m\]\u\[\e[00m\]:\[\e[34m\]\w\[\e[00m\]\[\e[35m\]$(__git_ps1 " (%s)")\[\e[00m\] $ '
export PS1
You can’t perform that action at this time.