Skip to content

Instantly share code, notes, and snippets.

@arraytools
arraytools / test.nwt
Last active March 12, 2025 17:49
causative.nwt for testing
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<sbgn xmlns="http://sbgn.org/libsbgn/0.3">
<map id="causative.nwt" language="sif">
<extension>
<renderInformation
xmlns="http://www.sbml.org/sbml/level3/version1/render/version1" id="renderInformation" program-name="sbgnviz" program-version="6.0.1" background-color="#00000000">
<listOfColorDefinitions>
<colorDefinition id="color_1" value="#ffffffff"/>
<colorDefinition id="color_2" value="#323232"/>
<colorDefinition id="color_3" value="#ff8164"/>
@arraytools
arraytools / 0-readme.txt
Last active April 9, 2025 02:23
R shiny application with non-root output. Go to http://localhost:3838/myapp to see the shiny application.
$ tree
├── app
│ └── myapp
│ └── app.R
└── compose.yml
$ mkdir -p app/myapp
$ sudo chmod 777 app/myapp # shiny user can write
$ docker compose up
# Click the 'Write Output File' button
@arraytools
arraytools / ks_1sample.R
Last active June 12, 2025 17:20
Compare K-S test statistic calculated by hand (through ecdf() ) and by R (through ks.test() )
# 1. Generate sample data
set.seed(123)
sample_data <- rnorm(100, mean = 0, sd = 1) # A sample from a standard normal distribution
# 2. Define the theoretical CDF (for standard normal distribution)
# In R, pnorm() is the CDF for the normal distribution
theoretical_cdf <- function(x) pnorm(x, mean = 0, sd = 1)
# 3. Compute the ECDF of your sample
ecdf_sample <- ecdf(sample_data)
@arraytools
arraytools / local_image_download.R
Created July 28, 2025 01:13
Shiny Image Download Examples. 'remote_image_download.R' does not need local images. 'local_image_download.R' requires local files. To run the app, runApp('remote_image_download.R').
# This method assumes that the files 'casaos.png' and 'shiny-test.txt' exist in the 'www' subdirectory.
# They don't have to be in the 'www' subdirectory. If they're located elsewhere, modify the file paths accordingly.
library(shiny)
# UI
ui <- fluidPage(
titlePanel("Image Download Example"),
mainPanel(
@arraytools
arraytools / yt-int.sh
Created August 3, 2025 18:01
Download youtube video and caption using yt-dlp utility.
#!/bin/bash
# Usage: ./yt-int.sh <youtube_url>
if [ -z "$1" ]; then
echo "Usage: $0 <youtube_url>"
exit 1
fi
URL="$1"
@arraytools
arraytools / clock.py
Last active August 22, 2025 12:59
Create a simple digital clock using the pygame module
import sys
import time
import pygame
# Initialize pygame
pygame.init()
# Set up display (resizable)
WIDTH, HEIGHT = 400, 200
window = pygame.display.set_mode((WIDTH, HEIGHT), pygame.RESIZABLE)
@arraytools
arraytools / embed.html
Created December 7, 2025 00:03
Embed youtube video to an HTML page. Default is 1080p. No autoplay.
<!DOCTYPE html>
<html>
<head>
<title>YouTube Video Embedder (1080p Size)</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
}
@arraytools
arraytools / cox-age-confounding-sex.rmd
Created August 11, 2026 17:44
Create simulated survival data with age and sex as predictors, where males have younger ages. Demonstrate that sex alone cannot differentiate survival, but it can once adjusted for age.
---
title: "Confounding/Suppression in Cox Regression: The Role of Age in the Sex–Survival Association"
author: "Your Name"
date: "`r Sys.Date()`"
output:
html_document:
toc: true
toc_float: true
number_sections: true
theme: flatly
@arraytools
arraytools / MyRadioStations.m3u
Created August 26, 2026 18:13
Internet Radio
#EXTM3U
#EXTINF:-1,WBJC Classical
https://ice64.securenetsystems.net/WBJC
#EXTINF:-1,NBC News
https://d1si3n1st4nkgb.cloudfront.net/10502/88896001/hls/master.m3u8?ads.xumo_channelId=88896001
#EXTINF:-1,Bloomberg Radio
https://playerservices.streamtheworld.com/api/livestream-redirect/WBBRDCAAC.aac
#EXTINF:-1,WAMU
https://wamu.cdnstream1.com/wamu.mp3
#EXTINF:-1,WETA Classical
@arraytools
arraytools / Notes.md
Last active August 26, 2026 20:07
A simple example illustrating how to add a logging system to an R shiny code using Shiny's options(shiny.error = ...) hook.

The log file is saved under the working directory.

What this does correctly

  • log_file and log_message() set up your logging function — nothing special here, just a helper that appends timestamped lines to a file.
  • options(shiny.error = ...) registers a global hook. Whenever an error occurs anywhere in your app's reactive code and nothing catches it, Shiny calls this function before showing its default error UI to the user.
  • geterrmessage() retrieves the text of whatever error condition was just raised — that's what gets written to the log.

Caveats to be aware of