Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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"/>
1. The Elevator Pitch Summary
Prompt: "Summarise this paper in 3–5 sentences, as if you're explaining it to a colleague in an elevator ride."
2. Key Findings Extraction
Prompt: "List the top 5 key findings or conclusions from this paper, along with a brief explanation of each."
3. Methodology Breakdown
Prompt: "Explain the methodology used in this study in simple terms. What are its strengths and potential limitations?"
4. Literature Review Assistant
@arraytools
arraytools / R-options.R
Last active February 16, 2025 01:48
Beyond Function Parameters: Using R Options for Dynamic Inputs. Demonstrate the idea behind the post "Using options() to inject a function’s internal variable for reproducible testing" https://brodrigues.co/posts/2025-02-13-testthat.html
calculate_total <- function(items) {
subtotal <- sum(items)
tax_rate <- getOption("TAX_RATE", default = 0.1) # Default 10% tax
total <- subtotal * (1 + tax_rate)
return(round(total, 2))
}
# Test the function with default tax rate
cart1 <- c(10, 20, 30)
print(calculate_total(cart1)) # Output: 66.00
@arraytools
arraytools / bitbucket.py
Created February 9, 2025 20:15
Return the name and the size of each bitbucket repositories. Step 1: Change username and app_password, Step 2: Run "python3 bitbucket_download.py". The app_password can be created from Avatar -> Personal settings from the dropdown menu on RHS. Navigate to App Passwords and then Access management -> App passwords.
import requests
from requests.auth import HTTPBasicAuth
username = "USERNAME"
app_password = "API_PASSWORD"
base_url = f"https://api.bitbucket.org/2.0/repositories/{username}"
def fetch_repositories(url):
response = requests.get(url, auth=HTTPBasicAuth(username, app_password))
response.raise_for_status() # Raises an error for bad status codes
@arraytools
arraytools / shiny_rainbow.R
Created January 2, 2025 21:31
A Shiny app to understand the `saturation` and `value` parameters in the rainbow() function
library(shiny)
# Define the UI
ui <- fluidPage(
titlePanel("Rainbow Color Palette"),
sidebarLayout(
sidebarPanel(
sliderInput("s_value", "Saturation (s):", min = 0, max = 1, value = 1, step = 0.01),
sliderInput("v_value", "Value (v):", min = 0, max = 1, value = 1, step = 0.01)
),
@arraytools
arraytools / simulation_logrank_test.R
Created December 2, 2024 21:55
Compare the effects of sample size on the log-rank test
library(survival)
# Function to generate survival data
generate_data <- function(sample_size, event_rate_group1, event_rate_group2) {
group <- c(rep(1, sample_size), rep(0, sample_size))
event_times <- c(rexp(sample_size, rate = event_rate_group1),
rexp(sample_size, rate = event_rate_group2))
observed <- rep(1, sample_size * 2) # Assuming all events are observed
data <- data.frame(group = group, event_times = event_times, observed = observed)
return(data)