Skip to content

Instantly share code, notes, and snippets.

View AdamJDuggan's full-sized avatar

Adam Duggan AdamJDuggan

  • Bluecrest HealthCare
  • Brighton
  • 07:44 (UTC -12:00)
View GitHub Profile
const formatTime = (value) => {
const units = ["hour", "min", "sec"];
const abs = Math.abs(value * 60 * 60);
if (abs < 1) return "0 hours";
return [
Math.floor(abs / (60 * 60)),
Math.floor((abs / 60) % 60),
Math.floor(abs % 60),
@AdamJDuggan
AdamJDuggan / gist:668c8d1f0bc69c062f6d6c9fef66619d
Created November 13, 2023 12:03
Retrive deleted values from Racoon staging datbase
const getBackReviewFiles = async () => {
const activites = await Firebase.firestore()
.collection("activity")
.where("timestamp", ">=", Firebase.firestore.Timestamp.fromDate(from))
.get()
.then((querySnapshot) => {
const docs = [];
querySnapshot.forEach((doc) => {
if (
doc.data().collectionId === "reviewfiles" &&
@AdamJDuggan
AdamJDuggan / gist:11329883f1a93b76e180e381ac98064d
Created July 31, 2023 14:17
Get array of times 15 minutes between startTime and span (number of hours)
const get15MinIntervals = (startDate, span) => {
const start = new Date(startDate);
const endTime = new Date(start);
endTime.setHours(endTime.getHours() + span);
const arr = [];
let minutes = 0;
while (start < endTime) {
const date = new Date(start);
const hours = minutes < 60 ? minutes + " mins" : minutes / 60 + " hrs";
arr.push({
@AdamJDuggan
AdamJDuggan / gist:4f88fc65d1adf2dee324d580d4675d06
Created July 3, 2023 11:09
Re-order items inside array with same id. Keep other items in same place
// Let's say we're moving 5 to the top,
// 5 should become index 0
// 1 should become index 1
// 2 should become index 4
// 6 should stay index 5
// 3 should stay index 3
// 4 should stay index 4
const fileSizeBytes = 2848208; // bytes
let fileSizeMB = fileSizeBytes / (1024 ** 2)
const fileStructure = {};
files.forEach(file => {
const split = file.name.split("/");
let parent = fileStructure;
let path;
split.forEach((part, index) => {
path = path ? path + "/" + part : part;
if(!parent[part]){
parent[part] = {type: index < split.length - 1 ? "dir" : "file", path, children: {}};
}
const quickSort = (array) => {
if(array.length < 2) return array;
else {
const pivot = array[0];
const shiftedArray = array;
shiftedArray.shift();
const less = shiftedArray.filter(item => item <= pivot);
const greater = shiftedArray.filter(item => item > pivot);
return [...quickSort(less), pivot, ...quickSort(greater)];
}
/**
* Loop through the data from the parsed CSV and
* build up a flat XML string
*/
public function arrayToFlatXml($elements, $headers)
{
$xmlString = '';
foreach($elements as $elementKey => $element) {
$count = 1;
$xmlString .= "<" . array_keys($element)[0] ." value='". array_values($element)[0] ."'>".PHP_EOL;
const delimiter = "/";
export const TestId = (props = {}) => {
const component = props["data-testid"];
return (element, key) => {
const testId = [component, element, key]
.filter((v) => v !== undefined)
.join(delimiter);
return {
"data-testid": testId,
};
import { useState } from "react";
function useSuperContextState(initialState) {
const [errors, setErrors] = useState([]);
const [pending, setPending] = useState([]);
const [state, setState] = useState(initialState);
const setter = (payload) => setState(payload);