Skip to content

Instantly share code, notes, and snippets.

José María Mateos rinze

View GitHub Profile
View plot_map.R
data1 <- data.frame(location = c(rep(0, 10), 1:100, rep(100, 200), 100:1, rep(0, 10)),
style = 1)
#data1$style[(nrow(data1)-30):nrow(data1)] <- 2
data1$idx <- 1:nrow(data1)
plt1 <- ggplot(data1) + geom_line(aes(x = idx, y = location,
linetype = factor(style)),
rinze /
Created Sep 24, 2018 — forked from Geoyi/
Setting up your python development environment (with pyenv, virtualenv, and virtualenvwrapper)


When you're working on multiple coding projects, you might want a couple different version of Python and/or modules installed. That way you can keep each project in its own sandbox instead of trying to juggle multiple projects (each with different dependencies) on your system's version of Python. This intermediate guide covers one way to handle multiple Python versions and Python environments on your own (i.e., without a package manager like conda). See the Using the workflow section to view the end result.

Use cases

  1. Working on 2+ projects that each have their own dependencies; e.g., a Python 2.7 project and a Python 3.6 project, or developing a module that needs to work across multiple versions of Python. It's not reasonable to uninstall/reinstall modules every time you want to switch environments.
  2. If you want to execute code on the cloud, you can set up a Python environment that mirrors the relevant
View benford_2016_usa_elections.R
get_first_digit <- function(x) {
return(substr(x, 1, 1))
votes <- read_csv("")
rinze / lineas_rojas.R
Created Dec 21, 2015
Generador automático de líneas rojas para partidos políticos.
View lineas_rojas.R
coords <- data.frame(x1 = runif(NLINEAS, 0, 10),
x2 = runif(NLINEAS, 0, 10),
y1 = runif(NLINEAS, 0, 10),
y2 = runif(NLINEAS, 0, 10))
plt1 <- ggplot(coords) + geom_segment(aes(x = x1, xend = x2,
rinze / loo_cv_comparison.R
Last active Aug 29, 2015
Just a little reminder: be careful not to use leave-one-out with a perfectly balanced problem
View loo_cv_comparison.R
# Test data
group <- c(rep('groupA', 10), rep('groupB', 10))
data <- data.frame(group = group, var = c(rep(0, 10), rep(0, 10)))
# Leave-one-out
probs <- lapply(1:nrow(data), function(i) {
train <- data[-i, ]
test <- data[i, ]
rinze /
Last active Jan 15, 2019
Parser para los archivos .DAT del Ministerio del Interior y el archivo de códigos de municipios del INE y código en R para gráficas simples.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv
import codecs
import cStringIO
import os
from collections import namedtuple
def getParties(parties_file):
View gist:a8dfd32b80fac8d9d8e1
### Keybase proof
I hereby claim:
* I am rinze on github.
* I am rinzewind ( on keybase.
* I have a public key whose fingerprint is 67AF C4B2 E15C 4F4C 67BD 5F58 5ADF 9021 2630 80EC
To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am rinze on github.
  • I am rinzewind ( on keybase.
  • I have a public key whose fingerprint is C7F0 E413 1FFF 47C6 A2A7 F76B F4FE 866D 2948 FA19

To claim this, I am signing this object:

View header.R
localpath <- "/home/chema/tmp/kaggle/digits/"
if (["sysname"] == "Windows")
localpath <- "C:/temp/kaggle/digits"
testFile <- file.path(localpath, "test.Rda")
trainFile <- file.path(localpath, "train.Rda")
if(!file.exists(testFile) && !file.exists(trainFile)) {
testCSV <- file.path(localpath, "test.csv")
trainCSV <- file.path(localpath, "train.csv")
rinze / dataframe_matrix_timing.R
Last active Dec 21, 2015
Difference in timing for vectorized simple operations between an R matrix and a data.frame.
View dataframe_matrix_timing.R
# Timing measurement in R. Vectorized operation on matrix / data.frame
# Author: José María Mateos -
# For certain vectorized operations, it makes sense to convert your data.frame
# into a matrix. Even if you are using apply, the data frame iteration can be
# real slow.
# In this example, I will compute the Euclidean distance for a random vector
# and a random matrix / data.frame of thousands of elements. Operations will be
# done in two different ways: using the apply function over the columns and
You can’t perform that action at this time.