Skip to content

Instantly share code, notes, and snippets.

@johncolby
johncolby / colorbar.R
Created May 26, 2011 19:16
An R function to generate color bar legends for neuroimaging plots
# Function to plot color bar
color.bar <- function(lut, min, max=-min, nticks=11, ticks=seq(min, max, len=nticks), title='') {
scale = (length(lut)-1)/(max-min)
dev.new(width=1.75, height=5)
plot(c(0,10), c(min,max), type='n', bty='n', xaxt='n', xlab='', yaxt='n', ylab='', main=title)
axis(2, ticks, las=1)
for (i in 1:(length(lut)-1)) {
y = (i-1)/scale + min
rect(0,y,10,y+1/scale, col=lut[i], border=NA)
@leonelsr
leonelsr / bash_background.vbs
Last active March 14, 2024 02:26
Run bash (Windows Subsystem for Linux) in background, in order to keep background processes running in WSL
' Windows Devs said on the developer feedback asking for cron, deamons and background tasks:
' "This first release of Bash/WSL doesn’t support background tasks, cron jobs, daemons, etc.
' Currently, when you close your last bash shell console window, we tear-down the Linux process
' chain in order to conserve resources."
'
' That's the workaround for now.
' You can run it on boot, for example, and it'll keep a instance of bash running alone in the background
' allowing background processes to run on WSL.
Set WshShell = CreateObject("WScript.Shell")
@khakieconomics
khakieconomics / deep_loops_in_stan.R
Created August 8, 2018 22:52
Write your deep loops in Stan, not R
library(tidyverse); library(rstan)
# Some fake data
Individuals <- 1000
Sims <- 1000
Months <- 20
initial_values <- data.frame(customer_id = 1:Individuals, initial_value = rnorm(Individuals))
# outline the packages needed for this script
# pak::pkg_install("hadley/requirements")
# requirements::req_file("SNP_saturation.R")
# Input 1-2 sentences that describe what this does, when it was done, and why
if (!requireNamespace("parallel", quietly = TRUE)) {
install.packages("parallel")
}