Skip to content

Instantly share code, notes, and snippets.

View mcshaz's full-sized avatar

Brent McSharry mcshaz

  • Auckland
View GitHub Profile
@mcshaz
mcshaz / bonferroni-holm.R
Last active February 16, 2024 02:21
R code to apply bonferroni-holm adjustment for multiple comparisons
bonferroni.holm <- function(pValues, alpha=0.05, sidak=FALSE) {
pOrders <- order(pValues)
unadjusted.p <- pValues[pOrders]
undoOrder = order(pOrders)
m <- rev(rank(unadjusted.p, ties.method = "min"))
if (sidak) {
adjusted.alpha <- 1 - (1 - alpha) ^ (1 / m)
adjusted.p <- 1 - (1 - unadjusted.p) ^ m
} else {
adjusted.alpha <- alpha / m
// taken from https://stackoverflow.com/questions/71222556/how-to-convert-any-of-the-5-islamic-hijri-calendars-dates-to-any-of-18-world
// watch the temporal ECMAscript proposal which will make much of this obsolete - https://github.com/tc39/proposal-temporal
const formatters = {}
function getFormatter (calendar) {
const locale = 'en-u-ca-' + calendar
let returnFormatter = formatters[locale]
if (returnFormatter) return returnFormatter
const support = ['islamic-umalqura', 'islamic-civil', 'islamic-tbla', 'islamic-rgsa', 'islamic']
if (!support.includes(calendar)) throw new Error(`calendar must be one of '${support.join("', '")}'`)
@mcshaz
mcshaz / coalesceRespEpisodes.sql
Created August 31, 2022 01:50
Coalesce date ranges if < 24 hours between episodes and intervening either nothing or a lower level of support (higher EPI_CAT number)
-- =============================================
-- Author: Brent McSharry
-- Create date: Aug 2020
-- Description: Any periods off respiratory support OR with less respiratory support
-- (i.e. lower resp support = having a higher integer categorisation EPI_CAT)
-- which lasts for less than 24 hours, results in the episodes with greater
-- levels of support coalescing into a single episode
-- =============================================
CREATE FUNCTION [dbo].[ANZICSEpisodeSubmissionFields]
(
@mcshaz
mcshaz / SLK581.sql
Created July 29, 2022 02:33
SLK581 for SQL Server
CREATE Function [dbo].[StripNonAlphaCharacters](@Temp VarChar(50))
Returns VarChar(50)
AS
Begin
Declare @KeepValues as varchar(50)
Set @nonAlphaRegex = '%[^a-zA-Z]%'
While PatIndex(@nonAlphaRegex, @Temp) > 0
Set @Temp = Stuff(@Temp, PatIndex(@nonAlphaRegex, @Temp), 1, '')
Return @Temp
End
@mcshaz
mcshaz / NHIUnitTests.cs
Last active August 31, 2022 03:29
NZ NHI validator
using NHIValidation;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;
namespace TestNhi
{
public class NHIValidationUnitTests
{
private readonly ITestOutputHelper _output;
@mcshaz
mcshaz / oneSampleSurvival.R
Last active July 16, 2020 21:03
Comparing Survival of a Sample to a Standard Population (Finkelstein D, Muzikansky A, Schoenfeld D) using R
# see http://hedwig.mgh.harvard.edu/biostatistics/node/30 for the original paper and an excel spreadsheet with macros
# the spreadsheet does much the same in VBA, but with considerably more code
# unlike the vba spreadsheet, this also takes into acount the fraction of age in years at entry and exit (in creating per patient risk)
# if the age is greater than the maximum data (101 years old), each subsequent year is a repeat of the final annual risk available
library(survival)
oneSampleSurvival <- function(df, description) {
# NZ data between 0 and 100 for each year
# 10 years of population and death data was averaged (2009-2018) for each year of age until 89 years old
# data is then repeated in 5 yearly blocks as more granular data was hard to obtain
@mcshaz
mcshaz / reportValidity.js
Last active April 17, 2020 08:57 — forked from newhope/reportValidity.js
reportValidity polyfill for IE 10, 11
if (!HTMLFormElement.prototype.requestSubmit) {
HTMLFormElement.prototype.requestSubmit = function() {
const submitBtn = document.createElement('input');
submitBtn.type = 'submit';
submitBtn.hidden = true;
this.appendChild(submitBtn);
submitBtn.click();
this.removeChild(submitBtn);
};
}
@mcshaz
mcshaz / translateSvgMarkup.html
Last active June 28, 2019 08:30
cut and paste a section of svg markup, enter x & y translated, and all vectors will be offset (not bulletproof, but works for my markup)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>svg markup offset</title>
</head>
<body>
<form>
<label>
add to x
@mcshaz
mcshaz / ExampleController.cs
Last active September 8, 2022 23:43
simple implementation of the Google reCAPTCHA service in C#/.Net MVC5 using async method (as oppsed to ActionFilterAttribute)
namespace MyMvcApp.Controllers
{
public class HomeController : Controller
{
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ContactSubmit(
[Bind(Include = "FromName, FromEmail, FromPhone, Message, ContactId")]
ContactViewModel model)
{