Skip to content

Instantly share code, notes, and snippets.

@stephanbogner
stephanbogner / query.xml
Created June 23, 2017 16:10
[Overpass Turbo] Search for all motorways in a certain city
<osm-script output="xml" timeout="2000">
<id-query {{nominatimArea:Germany}} into="area"/>
<union>
<query type="way">
<has-kv k="highway" v="motorway"/>
<area-query from="area"/>
</query>
</union>
<union>
<item />
@stephanbogner
stephanbogner / script
Created July 3, 2017 12:56
Add Progress Bar in Apple's Numbers
// Results in ▓▓▓▓▓▓▓▓▓▓░░░░░░░░░
WIEDERHOLEN("▓";GANZZAHL(E2÷C2×20)) & WIEDERHOLEN("░";GANZZAHL((1−E2÷C2)×20))
// Inspired by https://twitter.com/year_progress/status/881482588732477440
// Script adapted from https://strobelstefan.org/?p=4126
@stephanbogner
stephanbogner / range-listener.js
Created July 4, 2017 11:00
[HTML/JS] Event Listener on Range sliders
<input type="range" min="-180" max="180" step="0.1" oninput="update(this.value)" onchange="update(this.value)">
python3 -m http.server
<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>
<script>
var lineString = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
13.0078125,
@stephanbogner
stephanbogner / client (website)
Created July 7, 2017 20:29
Simplest example of sending data from client to server in localhost network
<script src="socket.io.min.js"></script>
<script>
var ipOfLaptop = '192.168.2.107';
var definedPort = 8123;
var host = 'http://' + ipOfLaptop + ':' + definedPort;
var socket = io(host);
socket.emit('msg', 'test');
</script>
@stephanbogner
stephanbogner / beforeAndAfter.geojson
Last active November 13, 2017 14:03
Removes the loops from a lineString (Test to outline a lineString without having weird overlaps) Please note that this algorithm is not optimized for performance. I recommend only using it in command line tools
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stephanbogner
stephanbogner / convertAndInvertProjection.js
Created July 18, 2017 11:34
Simple example to convert coordinates from one projection into another one
// import
// - https://d3js.org/d3-geo.v1.min.js
// - https://d3js.org/d3-geo-projection.v2.min.js
// Keep x and y in the same range of values as coordinates
var x = 180;
var y = 90;
var fromXY = [x, y];
var fromLonLat = d3.geoEquirectangular().invert(fromXY);
var toXY = d3.geoMercator()(fromLonLat);
@stephanbogner
stephanbogner / keycodeGetting.html
Created July 18, 2017 14:43
Get the key code on press
<div id="console">
Press a key to see its key code
</div>
<script>
var cnsl = document.getElementById('console');
document.addEventListener("keyup", function(){
cnsl.innerHTML = event.keyCode;
});
</script>
@stephanbogner
stephanbogner / angleBetweenVectorAndPlane.js
Created July 19, 2017 07:39
Snippets writing apps with gyroscope and GPS
function getAngleBetweenVectorAndPlane(vector, plane) {
var angle = Math.asin(Math.abs(plane.x * vector.x + plane.y * vector.y + plane.z * vector.z) / (Math.sqrt(Math.pow(plane.x, 2) + Math.pow(plane.y, 2) + Math.pow(plane.z, 2)) * Math.sqrt(Math.pow(vector.x, 2) + Math.pow(vector.y, 2) + Math.pow(vector.z, 2))));
// http://www.vitutor.com/geometry/distance/line_plane.html
var direction = -vector.z / Math.abs(vector.z); // Because vector angle is always shortest and has no direction
angle = angle * direction * 180 / Math.PI;
return angle;
}