Skip to content

Instantly share code, notes, and snippets.

View rinze's full-sized avatar

José María Mateos rinze

View GitHub Profile
@rinze
rinze / Dockerfile-poc
Last active September 23, 2022 20:10
Files for kaniko issue #2261
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install -y wget gcc g++ redis supervisor libgl1 sudo \
vim less htop \
webp libwebp-dev \
&& apt-get clean
RUN sudo sed -i '/^bind/s/bind.*/bind 0.0.0.0/' /etc/redis/redis.conf
@rinze
rinze / plot_map.R
Created April 18, 2020 16:11
Plot code for https://rinzewind.org/blog-es/2020/donde-estamos.html Not pretty, but it does its job.
library(ggplot2)
theme_set(theme_bw(12))
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
rinze / build_dataset.py
Last active January 15, 2019 10:51
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):
@rinze
rinze / python_environment_setup.md
Created September 24, 2018 17:43 — forked from Geoyi/python_environment_setup.md
Setting up your python development environment (with pyenv, virtualenv, and virtualenvwrapper)

Overview

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
library(readr)
library(dplyr)
library(ggplot2)
get_first_digit <- function(x) {
return(substr(x, 1, 1))
}
votes <- read_csv("https://github.com/Prooffreader/election_2016_data/raw/master/data/presidential_general_election_2016_by_county.csv")
localpath <- "/home/chema/tmp/kaggle/digits/"
if (Sys.info()["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
rinze / lineas_rojas.R
Created December 21, 2015 21:37
Generador automático de líneas rojas para partidos políticos.
library(ggplot2)
NLINEAS <- 20
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
rinze / dataframe_matrix_timing.R
Last active December 21, 2015 15:58
Difference in timing for vectorized simple operations between an R matrix and a data.frame.
# Timing measurement in R. Vectorized operation on matrix / data.frame
# Author: José María Mateos - jmmateos@ieee.org
#
# 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
@rinze
rinze / mariano.ijm
Last active December 20, 2015 18:08
ImageJ macro for generating de Mariano Rajoy hybrid image at http://www.flickr.com/photos/rinzewind/9458528864/.
open("C:\\temp\\barcenas.tif");
run("32-bit");
run("Mean...", "radius=30");
open("C:\\temp\\mariano.tif");
run("32-bit");
run("Duplicate...", "title=mariano-1.tif");
run("Mean...", "radius=20");
imageCalculator("Subtract create 32-bit", "mariano.tif","mariano-1.tif");
imageCalculator("Add create 32-bit", "Result of mariano.tif","barcenas.tif");
selectWindow("barcenas.tif");
@rinze
rinze / ingresos.R
Last active December 14, 2015 18:19
El script que he usado para las gráficas https://twitter.com/Rinze/status/310774361588133888 y https://twitter.com/Rinze/status/310774425563836417. El segundo fichero saca https://twitter.com/Rinze/status/310779666774515714 El siguiente enlace permite acceder a los mismos datos que he usado yo (tiene información de más países, yo me he quedado c…
# Eustat data analysis
library(ggplot2)
eustat <- read.csv(file = "/tmp/ilc_di01_1_Data.csv", na.string = ":")
eustat$Value <- gsub(" ", "", eustat$Value)
eustat$Value <- as.numeric(eustat$Value)
spain <- eustat[eustat$GEO == "Spain" &
eustat$CURRENCY == "Purchasing Power Standard" &
eustat$INDIC_IL == "Top cut-off point",