Skip to content

Instantly share code, notes, and snippets.

Ananda Mahto mrdwab

Block or report user

Report or block mrdwab

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View jpeg_comic_resize2cbz.sh
#!/bin/bash
# Reduces the size of oversized jpegs, optimizes them, and compresses them to a cbz format
# Set the output file based on the input directory
filename=$(basename "$PWD").cbz
# Resize the jpegs to 50% of their original dimensions.
# NOTE: THIS OVERWRITES THE EXISTING FILES!
echo '>>>>> RESIZING JPEGS >>>>>'
View keybase.md

Keybase proof

I hereby claim:

  • I am mrdwab on github.
  • I am mrdwab (https://keybase.io/mrdwab) on keybase.
  • I have a public key ASAV-O-osZ6SCQGHU-TpoJ_GM0tId8y8FyXoXxMHo8Gl-wo

To claim this, I am signing this object:

@mrdwab
mrdwab / cSplit_e.R
Created Mar 8, 2018
Faster versions of `cSplit_e`, `numMat`, and `charMat`.
View cSplit_e.R
cSplit_e_new <- function (indt, splitCols, sep = ",", mode = "binary", type = "numeric",
drop = FALSE, fixed = TRUE, fill = NULL) {
indt <- setDT(copy(indt))
if (is.numeric(splitCols)) splitCols <- names(indt)[splitCols]
if (length(sep) == 1) sep <- rep(sep, length(splitCols))
if (length(sep) != length(splitCols)) stop("Wrong number of sep supplied")
if (length(mode) == 1) mode <- rep(mode, length(splitCols))
if (length(mode) != length(mode)) stop("Wrong number of mode supplied")
if (any(!mode %in% c("binary", "value", "count"))) {
@mrdwab
mrdwab / trim_ws.R
Last active Mar 8, 2018
Fast leading and trailing whitespace trimming for lists and vectors. Preserves `NA` values.
View trim_ws.R
trim_list <- function(x, relist = TRUE, convert = FALSE) {
x <- replace(x, lengths(x) == 0, NA_character_)
y <- unlist(x, use.names = FALSE)
y[!nzchar(y)] <- NA_character_
out <- trim_vec(y, TRUE)
if ((attr(out, "test") == "clean") & (!isTRUE(convert))) x
if (isTRUE(convert)) out <- type.convert(out, as.is = TRUE)
if (isTRUE(relist)) {
out <- split(out, factor(rep.int(seq.int(length(x)), lengths(x))))
if (is.null(names(x))) unname(out) else `names<-`(out, names(x))
@mrdwab
mrdwab / cSplit_fread_tests.R
Last active Mar 10, 2018
Using `fread` as the workhorse for `cSplit`.
View cSplit_fread_tests.R
dt1 <- fread("V1 V2 V3
x b;c;d 1
y d;ef 2
z d;ef 3
m tmp 4
n tmp 5
n x;yz 5")
dt1[4, V2:=''] # this record will be lost because V2 value is empty string
dt1[5, V2:=NA_character_] # NA value is processed correctly
View SO48607092.R
library(tidyverse)
library(data.table)
library(microbenchmark)
set.seed(1)
s <- sample(5, 10000, TRUE)
Sample <- rep(seq_along(s), s)
df <- data.frame(Sample,
motif = sample(LETTERS[1:10], length(Sample), TRUE),
chromosome = sample(2, length(Sample), TRUE))
View html5-video-presentation.html
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<style>
video {
width: 100%;
height: auto;
}
</style>
</head>
@mrdwab
mrdwab / SO43350554.R
Created Apr 12, 2017
Output comparison and timings for different approaches posted at Q#43350554 at Stack Overflow.
View SO43350554.R
# https://stackoverflow.com/questions/43350554/r-filling-in-empty-variables
fun1 <- function() {
apply(t(df), 2, function(x) {
conds <- rowSums(cbind(x, dplyr::lag(x), dplyr::lead(x)), na.rm = T)==2
x[conds] <- 1
x
}) %>% t()
}
View keybase.md

Keybase proof

I hereby claim:

  • I am mrdwab on github.
  • I am anandakpec (https://keybase.io/anandakpec) on keybase.
  • I have a public key whose fingerprint is DA48 E710 3EDA 383B F911 85F4 95AD 8366 3CB7 5B67

To claim this, I am signing this object:

@mrdwab
mrdwab / server.R
Last active Mar 1, 2016
KoBo Data Viewer (Shiny)
View server.R
# server.R
library(shiny)
shinyServer(function(input, output) {
## Start by creating a reactive version of the dataset listing. This
## will then let us access the data for use in dynamically creating
## the listing of the available datasets. We only need the "id"
## and "title" datasets.
You can’t perform that action at this time.