Skip to content

Instantly share code, notes, and snippets.

View pgmoir's full-sized avatar
:octocat:
Working

Phil Moir pgmoir

:octocat:
Working
  • Captur Limited
  • UK
View GitHub Profile
@pgmoir
pgmoir / map.geojson
Last active September 3, 2021 20:41
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pgmoir
pgmoir / PreviewImage.js
Last active March 9, 2023 09:23
Responsive resize of canvas to match inserted image and plot/tag points that stay in location during resize
import React, { useRef, useEffect } from 'react';
const scaleWidth = 500;
const scaleHeight = 500;
/*
topImage is an object
{
image: String, // name of image
imageUrl: String, // full url of remote hosted image
@pgmoir
pgmoir / reactjs-convert-line-breaks.js
Created February 26, 2020 10:47
ReactJS - convert line breaks
const addLineBreaksToParagraph = string =>
string.split('\n').map((text, index) => (
<p key={index}>
{text}
</p>
));
// e.g.
<div>{addLineBreaksToParagraph(heading)}</div>
@pgmoir
pgmoir / depthOfArrayExample.js
Created May 21, 2019 12:27
Calculate depth of array
const arr = [[["blah", 876, true], [3, 23, 56], ["hjdfhkjhk", false, -1]]];
const arr1 = [["blah", 876, true], [3, 23, 56], ["hjdfhkjhk", false, -1]];
const arr2 = [[["blah", 876, true], [[98728713,918723987,1283787],3, 23, 56], [[98728713,918723987,1283787],"hjdfhkjhk", false, -1]]];
const arr3 = [[["blah", 876, true], [[98728713,[2376,81727],918723987,1283787],3, 23, 56], [[98728713,918723987,1283787],"hjdfhkjhk", false, -1]]];
const arr4 = [[["blah", 876, true], [[[[[98728713,918723987,1283787],3, [1263876,["sdhjh",[12,true,[12873,8273,128],94853],23, 56]]], [[98728713,918723987,1283787],"hjdfhkjhk"]]], false, -1]]];
const getDepthOfArray = (arr) => {
let depth = 0;
let included = [];
@pgmoir
pgmoir / html.json
Last active December 1, 2018 20:22
VSCode - code snippet for HTML with Bootstrap 4 and Font Awesome 5 from CDN
{
"Html for lft-concept": {
"prefix": "htmlbf",
"body": [
"<!DOCTYPE html>",
"<html>",
"<head>",
"\t<meta charset=\"utf-8\" />",
"\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">",
"\t<title>$0</title>",