Skip to content

Instantly share code, notes, and snippets.

View zeehio's full-sized avatar

Sergio Oller zeehio

View GitHub Profile
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 / 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
@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)
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 / extract_moodle_files.py
Created October 16, 2015 10:09
Copy files from moodle mbz into an ordered directory tree.
#!/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 / resolucio_producte_matrius.ipynb
Created December 10, 2013 17:33
Resolucio exercici producte matrius
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zeehio
zeehio / tensors_i_numpy.ipynb
Created December 10, 2013 11:23
Utilitzar tensors i numpy (contracció de tensors i indexat)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zeehio
zeehio / gen-statistics.sh
Last active February 17, 2023 08:37
Generate HTML page with CPU, RAM, and disk usage information for several SSH servers.TODO: There are too many SSH connections per server. Fixing that would speed up a lot the HTML generation.
#!/bin/bash
# Shell script to get disk usage, cpu usage, RAM usage,system load,etc.
# from multiple Linux servers and output the information on a single
# server in html format. Read below for usage/installation info
# *--------------------------------------------------------------------*
# * ORIGINAL WORK BY:
# * dig_remote_linux_server_information.bash,v0.1
# * Last updated on 25-Jul-2005*
# * Copyright (c) 2005 nixCraft project *
# * Comment/bugs: http://cyberciti.biz/fb/ *
@zeehio
zeehio / install-rstudio-server.sh
Last active December 29, 2015 15:19
Install rstudio-server and setup nginx on in order to have http://default_server/rstudio on Ubuntu precise (and other ubuntus probably)
#!/bin/bash -x
# Distribution codename:
which lsb_release >/dev/null|| (echo "Could not find lsb_release" ; exit 1)
which apt-get >/dev/null|| (echo "Could not find apt-get" ; exit 1)
codename=$(lsb_release -cs) # "precise"
# Add R repository:
rsourceslist="/etc/apt/sources.list.d/r_sources.list"
@zeehio
zeehio / buscar_elements.ipynb
Created November 25, 2013 11:32
Buscar elements i índexs a llistes i np.arrays
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.