Thursday, November 7, 2019

Write all tmux scrollback to a file

https://unix.stackexchange.com/questions/26548/write-all-tmux-scrollback-to-a-file


For those looking for a simple answer, just use prefix + :, then type in capture-pane -S -3000 + return (Replace 3000 with however many lines you'd like to save.) This copies those lines into a buffer.
Then, to save the buffer to a file, just use prefix + : again, and type in save-buffer filename.txt + return, replacing filename with whatever you'd like.

(By default prefix is ctrl + b.)

Friday, October 18, 2019

Update file permission using git

For example, add execute

git update-index --chmod=+x script.sh

Reference:
https://stackoverflow.com/questions/10516201/updating-and-committing-only-a-files-permissions-using-git-version-control

Thursday, October 3, 2019

Variance explained by PCs


    #Simulate a dataset with 4 hightly correlated variables
    x=rnorm(20)
    x=cbind(v1=x, v2=x+rnorm(20,sd=0.02), v3=x+rnorm(20,sd=0.01), v4=x+rnorm(20,sd=0.03))
    #check correlation matrix
    cor(x)
    #Compute variances of the original variables
    apply(x,2,var)
    #Total variance
    (total=sum(apply(x,2,var)))

   #Compute PCA. Note here we don't center or scale the data just to keep the original variance
    pca=prcomp(x,center = FALSE, scale. = FALSE)
    pca
    #Check variance explained by the PCs
    pca$sdev^2
    #Variance can also be computed from rotated data or PCA scores
    apply(pca$x,2,var)
    #Compare the sum of total variances by the PCs, which should equal to the total variance of the original variables
    sum(pca$sdev^2)
    #Proportion of variance explained by PCs
    pca$sdev^2/total
    #Check correlation between the original variables and PC1
    apply(x,2,cor,y=prcomp(x)$x[,'PC1'])
    #Check correlation between the original variables and PC2
    apply(x,2,cor,y=prcomp(x)$x[,'PC2'])
    #Check correlation between the original variables and PC3
    apply(x,2,cor,y=prcomp(x)$x[,'PC3'])
    #Check correlation between the original variables and PC4
    apply(x,2,cor,y=prcomp(x)$x[,'PC4'])

    #Now let us compare PCs with a new "naive" coordinate: the mean across variables
    average=rowMeans(x)
    #variance of average values
    var(average)
    #Proportion of variance explained by average
    var(average)/total
    #Check correlation between the original variables and average
    apply(x,2,cor,y=average)

Tuesday, August 13, 2019

wget download a directory recursively

https://stackoverflow.com/questions/273743/using-wget-to-recursively-fetch-a-directory-with-arbitrary-files-in-it
 
wget -r -nH --cut-dirs=2 -np --reject="index.html*" http://mysite.com/dir1/dir2/data

Monday, July 22, 2019

Glue/combine mutiple pdf pages into one single page


From https://superuser.com/questions/366490/how-to-merge-multiple-pdf-files-onto-one-page-with-pdftk

Ole Tange's answer:

pdfjam Page1.pdf Page2.pdf --nup 2x1 --landscape --outfile Page1+2.pdf
It puts 2 pages on one page horizontally (1 row, two columns).
 
 
If you wanted to glue pages vertically, use --nup 1x2 --no-landscape
 
If you wanted no auto-scaling of pages (mine stretches output to fill a4 by default), use --noautoscale true 
 

Friday, March 8, 2019

Shinyapps.io - Getting started

https://shiny.rstudio.com/articles/shinyapps.html

Create a shinyapps.io account

Go to shinyapps.io and click “Dashboard.” The site will ask you to sign in using your email and password, your Google account, or your GitHub account.

Publish app


library(rsconnect) 
rsconnect::setAccountInfo(name="", token="", secret="") 
deployApp(appDir=getwd())

# if Bioconductor packages are required, run the following before deployApp
library(BiocManager)
options(repos = BiocManager::repositories())

Monday, February 18, 2019

Using Box under Linux

lftp
lftp :~> set ftps:initial-prot ""
lftp :~> set ftp:ssl-force true
lftp :~> set ftp:ssl-protect-data true
lftp :~> open ftps://ftp.box.com:990
lftp ftp.box.com:~> user username@xxxx.edu
Password:
lftp username@indiana.edu@ftp.box.com:~> ls
...

See original post
https://uisapp2.iu.edu/confluence-prd/display/SOICKB/Using+Box+under+Linux