Skip to content

Instantly share code, notes, and snippets.

View mfansler's full-sized avatar

Mervin Fansler mfansler

View GitHub Profile
@mfansler
mfansler / LICENSE-CC0
Last active September 11, 2024 07:32
Conda Forge R Team Scraps
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
@tomsing1
tomsing1 / subsample_bam.sh
Created June 7, 2021 21:58
Shell script to sub-sample a BAM file
# Shell function to subsample to a fixed number of alignments,
# requiring the sambamba and samtools suites to be available.
# see https://www.biostars.org/p/76791/
function SubSample {
local FACTOR=$(samtools idxstats $1 | cut -f3 | \
awk -v COUNT=$2 'BEGIN {total=0} {total += $1} END {print COUNT/total}')
if [[ $FACTOR > 1 ]]
then
echo '[ERROR]: Requested number of reads exceeds total read count in' $1 '-- exiting' && exit 1
@laggardkernel
laggardkernel / chpwd-equivalent-in-bash.md
Last active September 5, 2024 20:11
Create chpwd Equivalent Hook in Bash #bash #hook #zsh

There's not a complete hook system designed in Bash when compared with other modern shells. PROMPT_COMMAND variable is used as a hook in Bash, which is equivalent to precmd hook in ZSH, fish_prompt in Fish. For the time being, ZSH is the only shell I've known that has a chpwd hook builtin.

PROMPT_COMMAND

If set, the value is interpreted as a command to execute before the printing of each primary prompt ($PS1).

https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-Variables

chpwd Hook in Bash

@hyginn
hyginn / makeMD5.md
Last active January 29, 2023 17:39
The making of MD5 files
# Author: Boris Steipe (ORCID: 0000-0002-1134-6758)
# License: (c) Author (2019) + MIT
# Date: 2019-01-17

What are MD5 files good for anyway?

I recently contributed to Siegfried Köstlmeier's qrandom package and overlooked to update the package MD5 file. That got me thinking - these files are actually not mentioned in Writing R Extensions, and they are not mentioned in Hadley Wickham's R Packages either. We find them in the wild - but I did not find an explicit source regarding their format. In fact, there is a puzzled post from 2016 by Matthew Lueder on Stack Overflow "What is the MD5 file in R packages used for? How is it generated?" ... and the sole answer on the page misunderstood the question.

@hfossli
hfossli / standard.sh
Last active September 19, 2024 05:27
Standard bash script format
#!/bin/bash
CLEAR='\033[0m'
RED='\033[0;31m'
function usage() {
if [ -n "$1" ]; then
echo -e "${RED}👉 $1${CLEAR}\n";
fi
echo "Usage: $0 [-n number-of-people] [-s section-id] [-c cache-file]"
@nick3499
nick3499 / filter_map_collect.rs
Last active May 26, 2020 13:10
Rust: Filter Range, Map, Collect
fn main() {
let rng = 0..30;
let rng_even_cubed = rng.filter(|n| is_even(*n))
.map(|n| n * n * n)
.collect::<Vec<i32>>();
println!("{:?}", rng_even_cubed);
}
fn is_even(n: i32) -> bool {
n % 2 == 0
@luiscape
luiscape / install_packages.sh
Created January 16, 2017 14:36
Install Python dependency packages from requirements.txt using conda.
#
# Original solution via StackOverflow:
# http://stackoverflow.com/questions/35802939/install-only-available-packages-using-conda-install-yes-file-requirements-t
#
#
# Install via `conda` directly.
# This will fail to install all
# dependencies. If one fails,
# all dependencies will fail to install.
@mcg1969
mcg1969 / spaces.md
Last active November 12, 2021 14:28
Conda hackery: namespaces

Conda Proposal: namespaces

Motivation

We would like to position Conda as a language-agnostic package manager, but at present it maintains a distinct bias towards Python. Given its origins this was expected and, frankly, reasonable. Nevertheless, as we begin to use it to subsume other packaging ecosystems, such as CRAN, NPM, Ruby Gems, etc., we are going to want to overcome this history; and one key challenge is to address naming conflicts across platforms.

## This will allow you to use dplyr functions with Bioconductor's
## S4Vectors::DataFrame class. They simply call "as.data.frame" on
## DataFrame objects and then pass them to the methods for
## "data.frame". Note that this entails conversion of S4 vector
## columns to primitive vectors. No attempt is made to convert the
## results back to DataFrame, since such a conversion would not
## restore S4 vector columns that were converted to primitive vectors.
library(S4Vectors)
library(dplyr)
@davfre
davfre / bamfilter_oneliners.md
Last active August 4, 2024 03:10
SAM and BAM filtering oneliners