Skip to content

Instantly share code, notes, and snippets.

#' bighead - show subset in each dimension
#' @description like head but in all dimensions
#' @param obj - indexable object: vector, data.frame, matrix, or array
#' @param ntotal - total maximum elements to show
bighead <- function(obj, ntotal=100){
# dimension of object (dataframe = 2D)
dims <- dim(obj)
# vectors has NULL dim. Special case: set dim to length
if(is.null(dims)) dims <- c(length(obj))
ndim <- length(dims)
global $conf;
$my_pages = file($conf['indexdir'] . '/page.idx');
# don't care about titles -- but might in the future
#$my_titles = file($conf['indexdir'] . '/title.idx');
# $title = trim($my_titles[$id]);
# $title = empty($title)?($key."**"):$title;
$my_dates_html = array();
foreach($my_pages as $id => $page) {
@WillForan
WillForan / lncdr_waterfall_plot.R
Last active October 20, 2023 18:38
using R and LNCDR for a visit age waterfall plot
# get needed libraries
install.packages(c('remotes','readxl', 'ggplot2'))
remotes::install_github('LabNeuroCogDevel/LNCDR')
library(LNCDR)
# read in data
# expects a row per visit with a column for id shared across visit and age at visit
# TODO: replace my_data.xlsx with actual excel document path/name
mydata <- readxl::read_xlsx("my_data.xlsx")
library(ggplot)
library(gamm4)
library(dplyr)
library(checkmate) # for expect_subset dataframe names test
met_res_for_roi <- function(MRSI_input, this_roi, met_name, minage=18, maxage=25) {
# have columns we need
expect_subset(c("roi", "age", "dateNumeric", met_name), names(MRSI_input))
roi_met <- MRSI_input %>%
teapot: teapot.cc
g++ -o teapot teapot.cc -lGL -lGLU -lglut
@WillForan
WillForan / RH_ds2_long_density.r
Created April 6, 2022 20:03
density plot with disparate scaling
library(ggplot2)
library(dplyr)
library(cowplot)
theme_set(theme_cowplot())
load("ds2_long.rdata")
# Smith is different than the other two
combine_ds2_long %>% split(.$study) %>% lapply(function(x) summary(x$value)) %>% bind_rows
# Min. `1st Qu.` Median Mean `3rd Qu.` Max. `NA's`
# <table> <table> <table> <table> <table> <table> <table>
@WillForan
WillForan / gamesbyemail_gambit_territory_count.js
Created October 12, 2020 19:12
count territories: update each gamesByEmail.com Gambit players status box w/ territory count
colors={'255, 255, 0': 'Yellow', '0, 255, 0': 'Green', '255, 0, 255': 'Magenta', '255, 0, 0': 'Red', '0, 255, 255': 'Cyan', '0, 0, 255': 'Blue' };
cnt={};
a=[... document.querySelectorAll('div[style~="background-color:"]')].map(x=>colors[x.getAttribute('style').replace(/.*background-color: rgb\((.*?)\); color.*/,'$1')]).forEach(function(x) {cnt[x] = cnt[x]===undefined?1:cnt[x]+1});
Object.keys(cnt).forEach(k=>$('font[title="'+k+'"]').children[2].innerHTML+= ", " + cnt[k] + "terr.")
library(ggplot2)
library(dplyr)
library(tidyr)
theme_set(cowplot::theme_cowplot())
eog <- read.csv('eog_cal/eeg_data_20200921.csv')
subjData <-
eog %>%
unite(ld8, LunaID, ScanDate) %>% # remove LunaID and scanDate columns. replace with ld8
mutate_at(vars(matches('Error')), abs) %>% # abs delta columns
@WillForan
WillForan / bids_heuristic.py
Created June 2, 2020 02:27
[heudiconv] MIA: bvec+bval
import os
def create_key(template, outtype=('nii.gz',), annotation_classes=None):
if template is None or not template:
raise ValueError('Template must be a valid format string')
return template, outtype, annotation_classes
def infotodict(seqinfo):
#!/usr/bin/env bash
#
# 20200414WF - init
# get all neuro study subjects by cursor
#
CURSORS=(
"eyJvZmZzZXQiOjI1fQ==" \
"eyJvZmZzZXQiOjEwMH0=" \