Skip to content

Instantly share code, notes, and snippets.

View peterdalle's full-sized avatar

Peter M. Dahlgren peterdalle

View GitHub Profile
@peterdalle
peterdalle / ping_cron_every_minute.ps1
Created July 19, 2021 07:41
Will simulate a scheduled service and run this URL every minute
$Url = "https://localhost:44399/cron.ashx?key=xxx"
do{
Write-Output "$(Get-Date)"
(Invoke-WebRequest $Url).Content
Write-Output ""
Start-Sleep -Seconds 60
}while(1 -eq 1)
@peterdalle
peterdalle / CopyTitleUrlBookmarklet.md
Created October 7, 2020 09:34
Bookmarklet: copy document title and URL to clipboard + highlighted text

Copy title and URL to clipboard bookmarklet

A bookmarklet to copy the document title and page URL to the clipboard. If you select/highlight text on the web page, the text is appended to the beginning of the text.

Full version:

javascript: (
function () {
	let selection = "";
@peterdalle
peterdalle / medyad.r
Created February 4, 2020 22:31
MEDYAD - Easy statistical mediation analysis with distinguishable dyadic data
# Downloaded from http://www.jjcoutts.com/medyad
# Coutts, J., Hayes, A. F., & Jiang, T. (2019). Easy statistical mediation analysis with distinguishable dyadic data. Journal of Communication
# https://doi.org/10.1093/joc/jqz034
# -----------------------------------------------------------------
#MEDYAD for SAS beta version 1.1;
#current as of 18 December 2019;
#Copyright 2019 by Jacob J. Coutts and Andrew F. Hayes;
@peterdalle
peterdalle / count_lines.sh
Created January 5, 2020 16:50
Count number of lines of code within Git project with specified file extensions
git ls-files | grep -P ".*(js|css|html|aspx|ascx|vb)" | xargs cat | wc -l
@peterdalle
peterdalle / download-videostream.sh
Created December 5, 2019 21:35
Download M3U8 videostream
ffmpeg -i "https://example.net/playlist.m3u8" -acodec copy -vcodec copy -absf aac_adtstoasc "output-video.mp4"
@peterdalle
peterdalle / offensive_programming.r
Created October 16, 2019 18:34
Offensive calculator programming
`+` <- function(x, y) {
val <- sum(x, y)
if (val > 1000000000) {
paste0("Don't push it")
} else if (val > 100000) {
paste0("So you like big numbers, huh? Well, I give you a big number. How about ", val ,"? Is that good enough for you?")
} else {
paste0("That's a fucking ", val)
}
}
@peterdalle
peterdalle / ggdag_gintonic_brainsize.r
Created September 22, 2019 07:57
Gin & tonic <--> brain size DAG
library(ggdag)
gin_dag <- dagify(happy ~ gin_tonic,
brain_size ~ happy,
gin_tonic ~ brain_size,
labels = c("brain_size" = "Hjärnstorlek",
"gin_tonic" = "Gin & Tonic",
"happy" = "Glad"),
exposure = "gin_tonic",
outcome = "brain_size") %>%
@peterdalle
peterdalle / highlight.tex
Created August 23, 2019 13:24
Yellow highlight text in LaTeX
\usepackage{color,soul}
And this is where we \hl{highlight the text} to make it stand out.
@peterdalle
peterdalle / get_all_git_repositories.ps1
Created August 3, 2019 14:06
Get all git repositories on local Windows machine
cd \
Get-ChildItem . -Attributes Directory+Hidden -ErrorAction SilentlyContinue -Filter ".git" -Recurse
@peterdalle
peterdalle / convert-confidence-interval-to-p-value.r
Last active December 7, 2018 20:36
Convert 95% confidence interval (estimate, odds ratio, risk ratio or hazard ratio) to a p-value
# Convert a 95% confidence interval to a p-value (two-sided).
# Based on:
# How to obtain the P value from a confidence interval
# BMJ 2011; 343 doi: https://doi.org/10.1136/bmj.d2304
# From estimate to p-value.
estimate.to.pvalue <- function(estimate, lower, upper) {
stderror = (upper - lower) / (2 * 1.96) # Get standard error.
z = estimate / stderror # Get test statistic.
p.value = exp(-0.717 * z - 0.416 * (z ^ 2)) # Get p-value.