Skip to content

Instantly share code, notes, and snippets.

View stevekm's full-sized avatar

Stephen Kelly stevekm

View GitHub Profile
@stevekm
stevekm / find_Rnw.sh
Last active September 28, 2015 16:09
Find my .Rnw files and search their contents for a string, using find and grep. There is probably a more elegant way to do this, but this one works.
#!/bin/bash
# look in my /Users/ dir
# look for the .Rnw files
# suppress the permission denied messages with this:
# 2> /dev/null
# these are the files to search:
FILES=$(find /Users/username -type f -name "*.Rnw" 2> /dev/null)
# this is the pattern I want to find within the files
@stevekm
stevekm / ls_dir_only.sh
Created October 2, 2015 13:58
Show only the directories in the ls output
#!/bin/bash
ls -lF | grep /
# -F = adds '/' to the end of dirs in the list
# grep for this
# so simple!
@stevekm
stevekm / grep_all_files.sh
Last active October 13, 2015 16:04
Search all my mardown files for a name, or an email address
#!/bin/bash
grep -F Name_to_find *.md
# can also use -l to just return the file name
# find someone's email address
grep -F -e @ *.md | grep name_to_find
@stevekm
stevekm / plotPCAWithSampleNames.R
Created October 29, 2015 18:34 — forked from igordot/plotPCAWithSampleNames.R
Modified DESeq2 plotPCA function with sample names and proportion of variance added. Sample names will be shown underneath each dot. The axis will display proportion of variance for each principal component. Tested using DESeq2 1.2.8, 1.6.2, and 1.8.1. The DESeq2 plotPCA function switched from lattice to ggplot2 in version 1.5.11.
plotPCAWithSampleNames = function(x, intgroup="condition", ntop=500)
{
library(RColorBrewer)
library(genefilter)
library(lattice)
# pca
rv = rowVars(assay(x))
select = order(rv, decreasing=TRUE)[seq_len(min(ntop, length(rv)))]
pca = prcomp(t(assay(x)[select,]))
@stevekm
stevekm / paste0_numbered_sample_names.R
Created November 18, 2015 22:09
Quickly paste "Sample1","Sample2",..."Sample'n' " to be added to a dataframe
paste0(rep("Sample",times=nrow(tmp_Table)),seq(1:nrow(tmp_Table)))
[1] "Sample1" "Sample2" "Sample3" "Sample4" "Sample5" "Sample6" "Sample7" "Sample8"
@stevekm
stevekm / find_grep_exec_xargs_example.sh
Created November 20, 2015 16:41
Examples of how to use -exec and xargs in combination with find and grep to find and search files
#!/bin/bash
# find all the shell scripts I have written that use the [ ] test function
# the [ needs to be escaped!
# using xargs
find ~/projects/ -type f -name "*.sh" -print0 | xargs -0 grep -l '\['
# using exec
find ~/projects/ -type f -name "*.sh" -exec grep -l '\[' {} \;
@stevekm
stevekm / jupyter_goes_here.txt
Last active November 25, 2015 00:55
The place to install Juptyer in OS X 10.11 El Capitan
Had trouble getting iPython, Jupyter, installed after upgrading to El Capitan OS X 10.11
using default pip, packages were getting installed to
/Library/Python/2.7/site-packages/
when trying to run `jupyer notebook`, the notebook package was not being found, couldn't run
`> jupyter: 'notebook' is not a Jupyter command`
uninstalled all packages that were installed to that dir
example:
@stevekm
stevekm / .bashrc
Created December 4, 2015 22:09 — forked from pcbulai/.bashrc
.bashrc file with some useful aliases and functions
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
### autocorrects cd misspellings, 'cd /sur/src/linus' >> 'cd /usr/src/linux' ###
@stevekm
stevekm / unzip_OS_X.sh
Created January 19, 2016 14:27
Unzip all .zip files in current directory into new directory of the same name. This is for OS X
#!/bin/bash
# unzip all files in current directory
# extract into new directory of the same name
for i in *.zip; do echo $i; echo ${i%.zip}; mkdir ${i%.zip}; unzip ${i} -d ${i%.zip}; done
@stevekm
stevekm / find_ignore_dotfiles.sh
Created January 20, 2016 16:23
find ignore dotfiles
#!/bin/bash
# in OS X
find -E . \( ! -regex '.*/\..*' \)
# vanilla bash
find . \( ! -regex '.*/\..*' \) -type f -name "filename"