Skip to content

Instantly share code, notes, and snippets.

View zeehio's full-sized avatar

Sergio Oller zeehio

View GitHub Profile
rm(list=ls())
paquets_CRAN <- c("reshape2",
"ggplot2", "colorspace",
"class", "e1071", "sfsmisc", "MASS",
"ChemometricsWithR", "ChemometricsWithRData",
"ptw", "signal", "dplyr", "gtools")
paquets_biocond <- c("DOSE","clusterProfiler","org.Hs.eg.db",
"Rgraphviz","pathview",
"KEGGgraph", "ALL","hgu95av2.db", "topGO",
@zeehio
zeehio / add_legend_title_space.R
Last active September 28, 2017 15:32
Function to add a space between the legend title and the legend values on a ggplot plot
#' Add space between the legend title and the legend items
#' @param gplt A plot created with ggplot
#' @param x How much space to add, given in x_unit units (default 0.5 lines)
#' @param x_unit Unit of x, "line" by default
#' @return A gtable object that can be plotted using plot()
#' @examples
#' library(ggplot2)
#' gplt <- ggplot(iris) + geom_point(aes(x=Sepal.Length, y = Sepal.Width, color = Species))
#' plt_gtable <- add_legend_title_space(gplt)
#' plot(plt_gtable)
@zeehio
zeehio / dplyr_and_dbi.R
Created October 6, 2017 15:46
Use of dplyr and DBI to connect to a sqlite database
loadNamespace("dplyr") # Like library, but forces us to use dplyr:: on all the calls
loadNamespace("DBI")
loadNamespace("RSQLite")
loadNamespace("dbplyr") # we don't directly use dbplyr, but dplyr uses it internally so better do the check now
`%>%` <- dplyr::`%>%` # We don't want to write dplyr::`%>%` every time
db_file <- "/tmp/iris55.db"
# This tryCatch makes sure that the database connection is properly disconnected
# at the end, even if there are errors in the middle of the script
setup1 = """
from itertools import zip_longest
def zip_equal(*iterables):
sentinel = object()
for combo in zip_longest(*iterables, fillvalue=sentinel):
if sentinel in combo:
raise ValueError('Iterables have different lengths')
yield combo
@zeehio
zeehio / fix_espeak_mycroft.sh
Created April 13, 2018 07:30
How to make Spanish espeak say 'mycroft' properly
#!/bin/sh
# 1. Check that espeak fails to transcribe mycroft:
echo "How espeak transcribes 'hola mycroft':"
espeak -v spanish -x -q --pho "hola mycroft"
# 'ola mik**'Oft
echo "How espeak should transcribe 'hola mycroft':"
espeak -v spanish -x -q --pho "hola máicroft"
# 'ola m'aik**Oft
@zeehio
zeehio / extract_moodle_files.py
Created November 26, 2018 08:06
Script to sort files from a moodle backup into a new directory.
#!/usr/bin/env python3
"""
Moodle provides a backup system for courses offering an mbz file. This is a zip file with
all the resources and files included and the needed metadata about the files encoded in XML.
This script gets an unzipped mbz directory and copies all the files from the course into
a directory tree with the same layout than the original moodle course.
unzip my_moodle_backup.zip
extract_moodle_files.py --source my_moodle_backup_FILES --destination sorted_course
@zeehio
zeehio / plot_interactive.R
Created January 30, 2019 07:48
Save the plotly plot as html
#' Plots in WebGL
#' @param plt A plot created with plotly or ggplot2
#' @param html_filename The file name where the plot will be saved
#'
#' @return The html_filename
#' @export
#'
plot_interactive <- function(plt, html_filename) {
htmltools::save_html(
@zeehio
zeehio / test.Rmd
Last active July 17, 2020 16:23
Reproduce Rstudio diagnostics spurious warnings
---
title: "Untitled"
author: "test"
date: "17/7/2020"
output: html_document
---
```{r}
xy <- tibble::tibble(
y = c(1, 2, 3, 4, 5, 6),
import os
def _clamp(x, min, max):
if x < min:
return min
if x > max:
return max
return x
def _read_cpu_quota_limit_cgroup():
@zeehio
zeehio / keybase.md
Created December 29, 2021 09:31
Keybase

Keybase proof

I hereby claim:

  • I am zeehio on github.
  • I am zeehio (https://keybase.io/zeehio) on keybase.
  • I have a public key whose fingerprint is 40B1 F8F3 B43C F786 4ED1 A0B6 20DA 0569 6BEB 2330

To claim this, I am signing this object: