Skip to content

Instantly share code, notes, and snippets.

View seabbs's full-sized avatar
🏠
Working from home

Sam Abbott seabbs

🏠
Working from home
View GitHub Profile
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active May 6, 2024 20:05
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@stephenhardy
stephenhardy / git-clearHistory
Created April 26, 2013 22:14
Steps to clear out the history of a git/github repository
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
@cvan
cvan / HOWTO.md
Last active March 20, 2024 17:56
How to serve a custom HTTPS domain on GitHub Pages with CloudFlare: *FREE*, secure and performant by default

Instructions

CloudFlare is an awesome reverse cache proxy and CDN that provides DNS, free HTTPS (TLS) support, best-in-class performance settings (gzip, SDCH, HTTP/2, sane Cache-Control and E-Tag headers, etc.), minification, etc.

  1. Make sure you have registered a domain name.
  2. Sign up for CloudFlare and create an account for your domain.
  3. In your domain registrar's admin panel, point the nameservers to CloudFlare's (refer to this awesome list of links for instructions for various registrars).
  4. From the CloudFlare settings for that domain, enable HTTPS/SSL and set up a Page Rule to force HTTPS redirects. (If you want to get fancy, you can also enable automatic minification for text-based assets [HTML/CSS/JS/SVG/etc.], which is a pretty cool feature if you don't want already have a build step for minification.)
  5. If you
@adamkucharski
adamkucharski / epinow2_infection.R
Last active February 26, 2024 14:18
Simulated infection recovery
# Example code for simulation recovery of infection dynamics from deaths for COVID -----------------------------------------
# Load libraries:
# install.packages("EpiNow2", repos = "https://epiforecasts.r-universe.dev")
library(EpiNow2)
# Simulate data and delays -----------------------------------------
# Simulate infections with a sharp drop
@swo
swo / polars_cheat_sheet.py
Last active December 6, 2023 03:24
Polars cheat sheet
import polars as pl
# Making data frames ------------------------------------------
# with dictionary
df = pl.DataFrame({
'name': ['foo', 'bar', 'baz'],
'bar': [0, 1, 2],
'qux': [0.0, 1.0, 2.0]
})
@sbfnk
sbfnk / weekly_forecasts.r
Created October 12, 2023 09:48
Weekly forecast plotting with EpiNow2
#' Aggregate daily forecasts to weekly forecasts
#'
#' Aggregate daily case forecasts from regional_epinow2 to weekly forecasts.
#'
#' @param inf List output from `EpiNow2::regional_epinow()`. No default.
#' @param week_start Week start day. Default is 1 (Monday).
#' @param summary_quantiles Quantiles for forecast summary. Default is median, plus upper and lower bound for 20\%, 50\% and 90\% forecasts.
#' @importFrom dplyr group_by summarise filter mutate select case_when contains
#' @importFrom tidyr pivot_wider
#' @importFrom purrr map_df
@zsusswein
zsusswein / convolve.stan
Last active October 2, 2023 08:41
Convolve two sequences in Stan with the FFT. Matches `convolve(x, rev(y), type = "open")` in R.
functions {
vector convolve(vector a, vector b) {
int na = num_elements(a); // Vector lengths
int nb = num_elements(b);
int n_zero_a = nb - 1; // Zero padding lengths
int n_zero_b = na - 1;
vector[nb] b_rev = reverse(b); // The reversed b vector
vector[na + n_zero_a] a_pad; // Instantiate zero padded vectors
wd <- system("echo $(git rev-parse --show-toplevel)", intern = TRUE)
setwd(wd)
source(paste0(wd, "/influenza/scripts/depends.R"))
output_dir <- fs::path(paste0(wd, "/influenza/papers/univariate/outputs"))
# nhs_data path for getting population sizes:
nhs_data_path <- "" # Removed path to influenza data + population catchments per trust
@mattjbayly
mattjbayly / Replace_multiple_strings.R
Last active October 16, 2022 05:42
Replace multiple strings across multiple text files
#' Replace multiple strings across multiple files with original values and replacement values.
#'
#' files - A character string of file names to work through.
#' f - A character string of original values that you want to replace.
#' r - A character string of replacement values (f->r).
multi_replace <- function(files="", f="", r=""){
file_line = data.frame() # (optional) tracking table
#loop through each file separately
for(j in 1:length(files)){
nl <- suppressWarnings(readLines(files[j])) # read file line by line
# Purpose: This is just a play model to think about time spent on large and big grants/opportunities and
# overall likelihood of a successful result (undefined, just general feel).
# 2080 is the hours in a year if working 40 hours (because everyone does that...)
using JuMP
using Ipopt
model = Model(Ipopt.Optimizer)
p1 = .05 # Probability of winning grant 1
sx1 = .4 # Probability of successful work (class 1)