Skip to content

Instantly share code, notes, and snippets.

View webbedfeet's full-sized avatar

Abhijit Dasgupta webbedfeet

View GitHub Profile
@webbedfeet
webbedfeet / find_peaks2.R
Created March 21, 2019 20:49
Finding peaks in a signal, based on work by Marcos Duarte (@demotu)
#' Detect peaks in data based on their amplitude and other features
#'
#' Translated from the Python version at https://github.com/demotu/BMC
#' License: MIT
#' Version: 1.0
#'
#' @param x 1-d array
#' @param mph (NA, number), optional (default = NA). Detect peaks wthat are greater than minimum peak height (if `valley=F`) or peaks that are smaller than maximum peak height (if `valley=T`)
#' @param mpd positive integer, optional (default = 1). Detect peaks that are at least separated by minimum peak distance (in number of data)
#' @param threshold positive number, optional (default = 0). Detect peaks (valleys) that are greater (smaller) than `threshold` in relation to their immediate neighbors
@webbedfeet
webbedfeet / analytic_wfm.py
Created June 24, 2018 16:29 — forked from sixtenbe/analytic_wfm.py
Peak detection in Python
#!/usr/bin/python2
# Copyright (C) 2016 Sixten Bergman
# License WTFPL
#
# This program is free software. It comes without any warranty, to the extent
# permitted by applicable law.
# You can redistribute it and/or modify it under the terms of the Do What The
# Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See
@webbedfeet
webbedfeet / rmspace.sh
Created April 19, 2018 01:30
Replace spaces in filenames/directories recursively
find . -name "* *" -print0 | sort -rz | \
while read -d $'\0' f; do mv -v "$f" "$(dirname "$f")/$(basename "${f// /_}")"; done
@webbedfeet
webbedfeet / conv2docx.sh
Created April 19, 2018 01:05
Converting *.doc into *.docx recursively in a directory structure
for file in $(find . -name "*.doc")
do
/Applications/LibreOffice.app/Contents/MacOS/soffice --convert-to docx $file
done
@webbedfeet
webbedfeet / sas_export.py
Created June 24, 2017 04:13 — forked from mndrake/sas_export.py
SAS dataset to sqlite wrapper of the sas7bdat python package
#!/usr/bin/python
# Filename: sas_export.py
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 06 18:40:09 2015
@author: David Carlson
modified version for sas7bdat 2.0.1 of Charlie Huang version at:
http://www.sasanalysis.com/2014/08/python-extension-functions-to-translate.html
"""
@webbedfeet
webbedfeet / common-sci-symbols.md
Created April 11, 2017 18:25 — forked from benmarwick/common-sci-symbols.md
Commonly used scientific symbols in pandoc markdown

Commonly used scientific symbols in pandoc markdown

encoding is UTF-8, needs pdflatex

per mille sign

  • plain text: ‰ (doesn't render properly in PDF)
  • HTML: ‰ (renders properly in PDF)
  • LaTeX: $\text{\textperthousand}$ (renders properly in PDF)

delta sign

@webbedfeet
webbedfeet / common-sci-symbols.md
Created April 11, 2017 18:25 — forked from benmarwick/common-sci-symbols.md
Commonly used scientific symbols in pandoc markdown

Commonly used scientific symbols in pandoc markdown

encoding is UTF-8, needs pdflatex

per mille sign

  • plain text: ‰ (doesn't render properly in PDF)
  • HTML: ‰ (renders properly in PDF)
  • LaTeX: $\text{\textperthousand}$ (renders properly in PDF)

delta sign

@webbedfeet
webbedfeet / rename_df.R
Created March 9, 2017 04:39
Renaming tables in a list-column
data(mtcars)
bl <- mtcars %>%
nest(-cyl) %>%
mutate(mod = map(data, ~lm(mpg~wt, data=.) %>% tidy()) %>%
mutate(mod = map(mod, ~setNames(., paste('mymod', names(.), sep='_')))) %>%
select(-data) %>%
unnest()
@webbedfeet
webbedfeet / insert_character.R
Created March 9, 2017 02:08
Inserting a character at a particular point in a string using R
# To put a particular character _ after the 10th position in a string
gsub('^([a-z]{10})([a-z]+)','\\1_\\2', x)
# or
library(stringr)
str_replace(x, '^([a-z]{10})([a-z]+]','\\1_\\2')
@webbedfeet
webbedfeet / whichfn.R
Created March 3, 2017 22:35
Identifying which package the currently accessible function is from
whichfn <- function(fun){
require(stringr)
str_match(capture.output(environment(fun)),'namespace:(\\w+)')[,2]
}