Skip to content

Instantly share code, notes, and snippets.

View malanx's full-sized avatar

Jordan Malan malanx

View GitHub Profile
@malanx
malanx / wnPoly.php
Created March 22, 2020 08:51 — forked from zhujunsan/wnPoly.php
winding number algorithm for the inclusion of a point in polygon
<?php
class Point
{
public $x;
public $y;
public function __construct($x, $y)
{
$this->x = $x;
@malanx
malanx / DominantColours.php
Created March 5, 2020 23:40 — forked from pgchamberlin/DominantColours.php
PHP class to extract dominant colours from an image using K-Means clustering. This features an extremely rough-and-ready (read: inefficient) implementation of K-Means which I wrote to run on PHP < 5.3. If you can use an up-to-date build of PHP then you can take advantage of some proper implementations that proper maths-type people have written f…
<?php
/**
* Dominant colours by k means derived from code by Charles Leifer at:
* http://charlesleifer.com/blog/using-python-and-k-means-to-find-the-dominant-colors-in-images/
*
* MagickWand docs: http://www.magickwand.org/
*
* Color transformation algorithms from EasyRGB: http://easyrgb.com/
*
@malanx
malanx / cspheader.php
Last active January 16, 2019 22:16 — forked from phpdave/cspheader.php
CSP Header for PHP or Apache or .htaccess - Content Security Protocol
<?
//CSP only works in modern browsers Chrome 25+, Firefox 23+, Safari 7+
$headerCSP = "Content-Security-Policy:".
"connect-src 'self' ;". // XMLHttpRequest (AJAX request), WebSocket or EventSource.
"default-src 'self';". // Default policy for loading html elements
"frame-ancestors 'self' ;". //allow parent framing - this one blocks click jacking and ui redress
"frame-src 'none';". // vaid sources for frames
"media-src 'self' *.example.com;". // vaid sources for media (audio and video html tags src)
"object-src 'none'; ". // valid object embed and applet tags src
"report-uri https://example.com/violationReportForCSP.php;". //A URL that will get raw json data in post that lets you know what was violated and blocked