Skip to content

Instantly share code, notes, and snippets.

View pachadotdev's full-sized avatar
🎯
Focusing

Mauricio "Pachá" Vargas Sepúlveda pachadotdev

🎯
Focusing
View GitHub Profile
@pachadotdev
pachadotdev / index.html
Last active January 13, 2017 23:24
Sankey - Constitución Abierta
<!doctype html>
<meta charset="utf-8">
<script src="http://d3plus.org/js/d3.js"></script>
<script src="http://d3plus.org/js/d3plus.js"></script>
<div id="viz"></div>
<script>
var nodes = [
@pachadotdev
pachadotdev / datos_totales.json
Last active January 17, 2017 16:07
Constitución Abierta - Encuentros locales versus participación en elecciones presidenciales por regiones
[
{
"region": "Tarapacá",
"comuna": "Iquique",
"poblacion": 145881,
"encuentros": 229,
"encuentros_10000hab": 15.698,
"pcent_elas": 1.525,
"pcent_votos": 0.821,
"idh": 0.766,
@pachadotdev
pachadotdev / encuentros_participacion_metropolitana.json
Created January 17, 2017 17:00
Constitución Abierta - Encuentros locales versus participación en elecciones municipales de la Región Metropolitana
[
{
"comuna": "Santiago",
"poblacion": 139180,
"encuentros_10000hab": 69.335,
"indice_participacion": 68.6176,
"color": "#717290"
},
{
"comuna": "Cerrillos",
@pachadotdev
pachadotdev / banned_visas_2016.R
Last active February 5, 2017 21:47
banned_visas_2016.R
############
# Libraries
############
packages_cran <- c("devtools", "stringi", "data.table")
download_cran <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg) > 0) {
install.packages(new.pkg, dependencies = TRUE)
# It is best to use r.squaredGLMM() function from the MuMIn package
# The original function was made by Jon Lefcheck
##############
# Dependencies
##############
libraries = c("lme4","nlme")
download_and_or_load <- function(pkg){
# See http://pacha.hk/2017-07-15_gnu_nongnu_homebrew.html
# XCode CLT
xcode-select --install
# Update Homebrew and add formulae
brew update
# Check for broken dependencies and/or outdated packages
brew doctor
@pachadotdev
pachadotdev / search_tweets.R
Created August 3, 2017 23:20
using rtweet instead of twitteR
if (!require("pacman")) install.packages("pacman")
p_load(rtweet,jsonlite,dplyr,readr)
key = "xxx" #retrieve this from dev.twitter.com under keys and tokens
secret = "yyy" #retrieve this from dev.twitter.com under keys and tokens
twitter_token = create_token("extract_data_with_r", key, secret, cache = TRUE)
saveRDS(twitter_token, file = "twitter_token.rds")
@pachadotdev
pachadotdev / eda.R
Last active September 13, 2017 14:58
# Librerias e importacion de datos
library(googlesheets)
library(dplyr)
library(tidyr)
library(lubridate)
library(ggplot2)
library(ggthemes)
library(viridis)
@pachadotdev
pachadotdev / neighbors.R
Last active September 13, 2017 20:47 — forked from andrewheiss/neighbors.R
Calculate which countries share a border
# Adapted from https://gist.githubusercontent.com/andrewheiss/926b9d60a26e29f6bf32/raw/a09ecbca4613381a782b93e8aeaa4132016205b7/neighbors.R
# Map libraries
# You must install geos (http://trac.osgeo.org/geos/) and
# gdal (http://www.gdal.org/) first.
# OS X: `brew install geos gdal`
# Ubuntu: sudo apt-get install libgeos-dev libgdal-dev libproj-dev
# Then install these packages from source
# install.packages(c("rgeos", "rgdal"), type="source")
@pachadotdev
pachadotdev / r_on_ubuntu_16_04.sh
Last active August 9, 2018 07:08
Install R on Ubuntu 16.04
# add CRAN to apt sources
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
printf '\n#CRAN mirror\ndeb https://cran.dcc.uchile.cl/bin/linux/ubuntu xenial/\n' | sudo tee -a /etc/apt/sources.list
# install R
sudo apt-get update
sudo apt-get install libxml2-dev libssl-dev libcurl4-gnutls-dev gfortran libopenblas-dev
sudo apt-get install r-base r-base-dev
# install common packages