Skip to content

Instantly share code, notes, and snippets.

View kirsty-forrester's full-sized avatar

Kirsty Forrester kirsty-forrester

  • Lytham St. Annes, England
View GitHub Profile
@kirsty-forrester
kirsty-forrester / nearestPartners.js
Created September 9, 2017 20:17
Results within 100km of central London
const https = require('https');
// Convert degrees to radians
const toRad = x => x * Math.PI / 180;
/**
* Calculate the distance between two sets of coordinates
*
* @param {array} [coords1] The first set of coordinates, in degrees
* @param {array} [coords2] The first set of coordinates, in degrees
@kirsty-forrester
kirsty-forrester / deepClone.js
Created September 9, 2017 20:00
Create a copy of an object
/**
* Deep clone an object
* Designed to handle objects with objects, arrays, and dates
* TODO: Handle other data types?
*
* @param {object} [obj] The object to clone
* @return {object} The cloned object
*/
const deepClone = (obj) => {

Keybase proof

I hereby claim:

  • I am kirsty-forrester on github.
  • I am frostyswirl (https://keybase.io/frostyswirl) on keybase.
  • I have a public key ASDaoU7yQs6yAxJNFJD5t1GVF6dglt1Wu7CK6s8vpOlI9wo

To claim this, I am signing this object:

@kirsty-forrester
kirsty-forrester / imagick_trim_tiled.php
Created February 22, 2013 15:36
Using the Imagick PHP class to trim excess background from images that have a tiled (repeating) background.
<?php
function trimTiled($imageFile)
{
// Get image and its dimensions
$image = new Imagick($imageFile);
list($width, $height, $type, $attr) = getimagesize($imageFile);
/**
* Create a new image that has the same dimensions as the original image
@kirsty-forrester
kirsty-forrester / imagick_palette.php
Created February 22, 2013 14:50
Using the Imagick PHP class to obtain an array of all the colors (with pixel counts) in a PNG image. This ignores transparent pixels and was only designed for images with a small amount of colors since it doesn't combine similar colors.
<?php
function getPalette($imageFile)
{
$image = new Imagick($imageFile);
$pixels = $image->getImageHistogram();
$palette = array();
foreach($pixels as $p){
// Below gives us an array in the format ('r' => 44, 'g' => 43, 'b' => 44, 'a' => 1)
$colors = $p->getColor();