Skip to content

Instantly share code, notes, and snippets.

@annatomka
annatomka / PolygonConvexityTest.js
Last active December 17, 2020 07:19
Determine in Javascript wheather a polygon is convex or not? (using Openlayers polygon and algorithm describe here: http://stackoverflow.com/questions/471962/how-do-determine-if-a-polygon-is-complex-convex-nonconvex)
function calculateAllCrossProduct(points) {
var lastSign = null;
for (var i = 2; i < points.length; i++) {
//calculate crossproduct from 3 consecutive points
var crossproduct = calculateCrossProduct(points[i - 2], points[i - 1], points[i]);
console.log(i + ". crossproduct from ("+ points[i - 2].x +" "+points[i - 1].x +" "+points[i].x +"): " + crossproduct);
var currentSign = Math.sign(crossproduct);
if (lastSign == null) {
//last sign init
@nikolavp
nikolavp / mail.py
Created February 25, 2013 15:55
A mail script that can move your mailman mbox files to a mysql table. You can call it with the following: ``` python3 mail.py sourc_file test mailman ``` note that this needs python3!
#!/usr/bin/env python
# vim: set sw=4 sts=4 et foldmethod=indent :
"""mbox_to_mysql: Import messages from mbox files to a mysql database """
# Mbox message handing is being done by mailbox module, which is a python core module.
# However, mbox FILE handling is done internally in this file, because the
# mailbox module does far more than we need, and takes up a lot of time to do it.
#
# Database handling is done through mysql.connector, which is not a core module;