Skip to content

Instantly share code, notes, and snippets.

@wulingyun
wulingyun / cleanMacMenu.sh
Created January 12, 2022 06:54
Clean the Open With menu in macOS
cd /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support
./lsregister -kill -r -all local, system, user; killall Dock;
@wulingyun
wulingyun / testCPU.sh
Created November 29, 2021 10:12
Linux CPU Testing
time echo "scale=5000; 4*a(1)" | bc -l -q
@wulingyun
wulingyun / 黑白网页.html
Created April 3, 2020 17:42
黑白悼念模式网页
<!-- 在网页的 head 部分加入以下内容,可以将网页改为黑白悼念模式 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<style type="text/css">
html {
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: url(data:image/svg+xml;utf8,;#grayscale);
@wulingyun
wulingyun / Sumatra.edt
Created June 19, 2016 14:23
Using Sumatra with WinEdt, add the following code to "WinEdt\Exec\Acrobat OpenDoc.edt", before the line: // GSView
// Sumatra?
FindInString(`%$('AcroRead')`,'SumatraPDF',1,2,1000,1);
IfOK(!"Relax;",!"JMP('not_sumatra')");
Run('%$("AcroRead"); -reuse-instance -inverse-search "\"%B\WinEdt.exe\" \"[Open(|%%f|);SelPar(%%l,8);]\"" "%P\%N.pdf"','%P',0,0,'%N.pdf - SumatraPDF',1,1);
DDEOpen('',"SUMATRA","control",1);
// send a DDE command to perform forward-search
// the format of the DDE command is [ForwardSearch("<pdffilepath>","<sourcefilepath>",<line>,<column>[,<newwindow>, <setfocus>])]
// if newwindow = 1 then a new window is created even if the file is already open
// if focus = 1 then the focus is set to the window
@wulingyun
wulingyun / updown_colors.R
Created June 19, 2016 12:46
Color function for green-red heatmap
updown_colors <- function(n = 50, down.col = 1/3, up.col=1, saturation = 1)
{
c(hsv(down.col, saturation, seq(1,0,length=n)), hsv(up.col, saturation, seq(0,1,length=n)))
}
@wulingyun
wulingyun / normal_test.R
Created June 19, 2016 12:43
Calculate normal test
# one sample normal test
norm_test1 <- function(x.n, x.mu, x.var, mu, side=0)
{
nu <- x.n - 1
z <- (x.mu - mu) / sqrt(x.var / x.n)
p <- p.value(pnorm, z, side=side)
data.frame(mean=x.mu, df=nu, statistic=z, p.value=p)
}
# two samples normal test
@wulingyun
wulingyun / t_test.R
Created June 19, 2016 12:41
Calculate student t-test
# one sample t-test
t_test1 <- function(x.n, x.mu, x.var, mu, side=0)
{
nu <- x.n - 1
t <- (x.mu - mu) / sqrt(x.var / x.n)
p <- p.value(pt, t, params=nu, side=side)
data.frame(mean=x.mu, df=nu, statistic=t, p.value=p)
}
# two samples t-test
@wulingyun
wulingyun / p_value.R
Created June 19, 2016 12:37
Calculate P-value
p_value <- function(cdf, z, params=numeric(0), side=0)
{
n <- length(params)
p <- switch(n+1,
cdf(z),
cdf(z, params),
cdf(z, params[1], params[2]),
cdf(z, params[1], params[2], params[3])
)
if (side < 0) p
@wulingyun
wulingyun / fold_change.R
Created June 19, 2016 10:44
Fold change with confidence interval
fold_change <- function(x, y, confidence.level=90, var.equal=F)
{
fc.interval(length(x), mean(x), var(x), length(y), mean(y), var(y), confidence.level, var.equal)
}
fc.interval <- function(x.n, x.mu, x.var, y.n, y.mu, y.var, confidence.level=90, var.equal=F)
{
mu <- x.mu - y.mu
if (var.equal) {
nu <- x.n + y.n - 2
@wulingyun
wulingyun / robust_fold_change.R
Created June 19, 2016 10:42
Robust fold change
robust_fold_change <- function(case, control)
{
m <- dim(case)[2]
n <- dim(control)[2]
fc.raw <- matrix(nrow=dim(case)[1], ncol=m*n)
for (i in 1:m) {
for (j in 1:n) {
fc.raw[, (i-1)*m+j] <- case[,i] - control[,j]
}
}