Skip to content

Instantly share code, notes, and snippets.

View Shians's full-sized avatar

Shian Su Shians

View GitHub Profile
@Shians
Shians / GIF-Screencast-OSX.md
Created December 8, 2016 00:53 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@Shians
Shians / star-wrapper.R
Last active January 2, 2018 00:51
Simple R wrapper for STAR aligner, called through system(), for Linux and macOS
star_align <- function(
read_files_in,
genome_dir,
out_file_type = "BAM",
sort_output = FALSE,
out_file_prefix = "",
nthreads = 2
) {
# use lexical scoping to grab cmd from outer scope
# saves having to pass in cmd at each step
@Shians
Shians / is_gzipped.cpp
Created March 9, 2018 03:31
Check if a file is gzipped by looking at magic numbers
bool is_gzipped(std::string filename) {
std::ifstream in_file;
char byte1, byte2;
in_file.open(filename, ios::binary|ios::ate);
if (in_file.is_open()) {
in_file.seekg(0, ios::beg);
std::string bytes;
in_file.read(&byte1, 1);
in_file.read(&byte2, 1);
@Shians
Shians / my_palette.R
Created January 4, 2019 03:56
Custom R Colour Palette
my_palette <- c(
"red3",
"royalblue4",
"green4",
"darkmagenta",
"gold",
"darkslategrey",
"darkorange3",
"palevioletred1",
"khaki4",
@Shians
Shians / google.R
Created March 1, 2019 00:29
Function to search google from R
# search google for query
google <- function(query) {
browseURL(glue::glue("https://www.google.com/search?q={URLencode(query)}"))
}
@Shians
Shians / lorem_ipsum.R
Last active March 1, 2019 02:50
Some gibberish that looks like code
lorem <- function(ipsum) {
dolor <- sit(amet, consectetur)
dolor <- adipiscing(dolor, elit, sed, do)
# aliqua Ut enim ad minim veniam, quis nostrud exercitation
eiusmod <- tempor(incididunt, ut)
labore <- et(dolor, magna)
# ullamco laboris nisi ut aliquip ex ea commodo consequat duis aute
reprehenderit <- numeric()
@Shians
Shians / ggplot2_custom_theme.R
Last active March 8, 2019 00:47
My preferred options for ggplot2
theme_set(
theme_classic() +
theme(
panel.grid.major = element_line(colour = "gray"),
plot.title = element_text(
face = "plain",
size = rel(20/12),
hjust = 1/2,
margin = margin(t = 10, b = 20)
)
@Shians
Shians / gist:827a20ad8a4896cab76cde95a0dd3d05
Last active July 12, 2019 07:37
Zsh-fish style command prompt
echo 'export PS1="\W \[\e[1;31m\]❯\[\e[1;33m\]❯\[\e[1;32m\]❯\[\e[0m\] "' >> ~/.bash_profile
. ~/.bash_profile
@Shians
Shians / Roxygen2_tags.md
Last active August 9, 2019 07:43
Roxygen2 Tags

This gist is a summary of roxygen2 tags, see roxygen2 docs for source of information.

Header Section

The initial three sections are automatically placed into title, description and details fields of the documentation. The details field is optional.

#' Title goes here
#'
#' Description goes here
@Shians
Shians / generate_nanopolish_index.R
Last active August 29, 2019 01:14
Generate nanopolish index in parallel
#!/usr/bin/env Rscript
library(fs)
library(rhdf5)
library(parallel)
library(purrr)
library(stringr)
library(dplyr)
library(tidyr)
index_fast5 <- function(fastq_file, fast5_dir) {