Skip to content

Instantly share code, notes, and snippets.

View zeehio's full-sized avatar

Sergio Oller zeehio

View GitHub Profile
@zeehio
zeehio / optiwine.sh
Created November 3, 2012 23:25 — forked from zipizap/hl2_optirun_start.sh
optirun and wine (on Ubuntu precise 12.04 64-bit)
#!/bin/bash
# This is a short script to load applications using bumblebee and wine
# on systems such as Ubuntu precise 12.04 64 bit using the discrete card.
# Usage example (the -opengl would be a parameter of the program "Frozen Throne.exe"):
# optiwine.sh "Frozen Throne.exe" -opengl
# Extra information:
# If you want to load programs with the integrated intel card instead, you may run them this way:
@zeehio
zeehio / crea_matrius.c
Last active December 23, 2015 22:19
Eina per utilitzar matrius bidimensionals en C de manera senzilla. Potser a algú que comenci amb C li resulta util.
/** \file crea_matrius.c
* \copyright No copyright reserved (consider it Public Domain or CC0 as you wish)
*/
#include <stdio.h>
#include <stdlib.h>
typedef double* DVector;
typedef DVector* DMatrix;
/** \fn CreateDVector
@zeehio
zeehio / python-funcions.md
Last active December 27, 2015 12:49
Una analogia de funcions en programació amb funcions a matemàtiques que espero que ajudi als estudiants que comencen a programar.

Funcions: Variables locals

En aquesta pàgina s'explica com s'utilitzen els arguments de funcions i com no s'utilitzen. Primer fem una analogia amb les funcions matemàtiques i després apliquem la mateixa lògica de les funcions matemàtiques a la programació.

La gràcia de fer servir funcions és que divideixes un problema (dibuixar una cara) en petites parts independents entre sí (ulls, nas, boca...).

Com documentar funcions i com aprofitar-ho amb ipython notebook

Com documentar funcions:

Python permet documentar funcions amb docstrings. Un docstring és una cadena de text que va just després de la definició de la funció i que descriu què fa la funció, quins arguments necessita i què retorna per pantalla.

def digueshola():
    """ Aquesta funció imprimeix hola per pantalla."""
    print "hola"
@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.
@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 / 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 / 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.
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)