Skip to content

Instantly share code, notes, and snippets.

View jtrecenti's full-sized avatar
🎯
Focusing

Julio Trecenti jtrecenti

🎯
Focusing
View GitHub Profile
@jtrecenti
jtrecenti / exemplo_hugo.R
Created August 26, 2014 22:38
exemplo de dplyr e ggplot2
require(dplyr)
require(ggplot2)
require(lubridate)
require(scales)
a <- c('2012-01-01')
a2 <- ymd(a)+days(1:1000)
a3 <- as.Date(a2)
@jtrecenti
jtrecenti / baixa_prod_tjsp.R
Last active August 29, 2015 14:06
Download de produtividades do TJSP
baixa_prod_tjsp <- function(d, mes='9', ano='2011', id_vara='1') {
curl <- getCurlHandle()
aux <- curlSetOpt(cookiejar = tempfile(), useragent = "R", followlocation = TRUE, ssl.verifypeer = FALSE, curl = curl)
url0 <- 'http://www.tjsp.jus.br/Institucional/CanaisComunicacao/Transparencia/Produtividade/Default.aspx'
html0 <- getURL(url0, curl=curl)
viewstate <- xmlGetAttr(getNodeSet(htmlParse(html0), "//input[@id='__VIEWSTATE']")[[1]], "value")
eventval <- xmlGetAttr(getNodeSet(htmlParse(html0), "//input[@id='__EVENTVALIDATION']")[[1]], "value")
post_var <- list('ctl00_ctl00_RadStyleSheetManagerportal_TSSM'=';|635458787180000000:2245c52c:8647d86b:6bfb0386:2c88367b:5c293c13:4405087d:c7942ac2:5aed19f8:55c8aca8:274b8a10:a7c49542:a1997d73:466a7156:33795bb3:ca77e845:4ad86637:a260866a;Telerik.Web.UI, Version=2014.1.403.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4:pt-BR:ca584452-327f-4858-bf00-fb22c6f6fd75:fe53831e:bc8339f7:1c2121e:e24b8e95',
@jtrecenti
jtrecenti / server.R
Last active August 29, 2015 14:08 — forked from Athospd/server.R
library(shiny)
library(magrittr)
shinyServer(function(input, output, session) {
#__________________________________________________________________________________
# The main named list that will be used in many other tasks.
listN <- list()
#__________________________________________________________________________________
@jtrecenti
jtrecenti / server.R
Last active August 29, 2015 14:08 — forked from Athospd/server.R
library(shiny)
library(magrittr)
shinyServer(function(input, output, session) {
#__________________________________________________________________________________
# The main named list that will be used in many other tasks.
#listN <- reactiveValues()
#__________________________________________________________________________________
@jtrecenti
jtrecenti / bruno.r
Created January 21, 2015 14:52
Associa bd do carlos cinelli com cadmun do pacote abjutils (fonte IBGE)
library(abjutils)
library(tidyr)
library(stringr)
f <- download.file('https://dl.dropboxusercontent.com/u/44201187/dados.rds', method='wget', 'cc.rds')
cc <- readRDS('cc.rds')
cc <- cc %>%
mutate(Municipio=str_trim(Municipio)) %>%
unite(municipio_uf, Municipio, Estado, sep='@')
@jtrecenti
jtrecenti / wikiave.R
Created October 21, 2015 20:45
Baixando do wikiave
library(httr)
library(xml2)
library(rvest)
library(readxl)
library(stringr)
library(dplyr)
library(ggplot2)
library(purrr)
library(stringdist)
@jtrecenti
jtrecenti / armas_homicidios
Created October 25, 2015 18:16
grafico de dispersao baseado em dados sobre armas e homicidios que vi no face.
library(ggplot2)
d <- data.frame(
label = c('USA', 'IEM', 'FIN', 'SUI', 'IRQ', 'SER', 'FRA', 'CAN', 'SUE', 'AUS', 'BRA'),
armas = c(90, 61, 55, 46, 39, 37.5, 32, 31.5, 31.5, 31, 8.8),
homic = c(4.2, 4.2, 2.2, 0.7, 2.0, 1.2, 1.1, 1.6, 1.0, 0.6, 21.0)
)
ggplot(d, aes(x = armas, y = homic, label = label)) +
geom_text() +
xlab('Armas por 100 mil habitantes') +
ylab('Homicídios por 100 mil habitantes')
@jtrecenti
jtrecenti / empresas.R
Created January 21, 2016 23:44
empresas do brasil - scraper em R
library(rvest)
library(httr)
library(tidyr)
library(dplyr)
library(stringr)
#' Tem captcha?
#'
#' Verifica se uma resposta tem captcha
#'
@jtrecenti
jtrecenti / universal.R
Last active April 13, 2016 18:05
scraper igreja universal
library(httr)
library(rvest)
library(dplyr)
library(stringr)
library(tidyr)
universal_pags <- function() {
universal_pag <- function(pag) {
link <- sprintf('http://www.universal.org/enderecos/busca/brasil/todas/%04d/', pag)
@jtrecenti
jtrecenti / mapa_distorcido.R
Last active February 11, 2016 16:16
Mapa distorcido SP
library(maptools)
library(magrittr)
library(getcartr)
library(ggplot2)
desacentuar <- function(x) {
gsub("`|\\'", "", iconv(x, to = "ASCII//TRANSLIT"))
}
###############################################################################