Skip to content

Instantly share code, notes, and snippets.

View leoniedu's full-sized avatar

Eduardo Leoni leoniedu

  • IBGE
  • Salvador, Brazil
View GitHub Profile
@leoniedu
leoniedu / eficiencia2024t1.R
Last active October 10, 2024 16:50
Eficiência do voto nas eleições para Prefeito no Brasil (1º Turno 2024 )
library(dplyr)
library(ggplot2)
library(ggrepel)
library(readr)
## votacao por municipio, candidato e cargo
vmc <- readr::read_rds("~/Downloads/20241007_151828_eleicao24_prefeitos_vereadores_finalizados.rds")
## por cargo, municipio, partido
vmp <- vmc%>%
@leoniedu
leoniedu / toTitleCasePT.R
Last active September 12, 2024 15:22 — forked from jjesusfilho/toTitleCasePT.R
Converts Portuguese strings to Title Case
#' Convertion to title case with lower case for some classes of words.
#'
#' In written Portuguese, when converting to title case, it is not usual
#' to keep in title case some words, like prepositions, conjunctions,
#' articles and some kinds of pronouns. This functions locates those
#' cases and converts them to lower case. Based on gist ToTitleCasePT https://gist.github.com/jjesusfilho/454192db8356eb9c486a02698338221a by https://github.com/jjesusfilho
#'
#' @param string vector of characters to be converted to title case
#' but with connector words (one-word prepositions and conjunctions)
#' and articles (both definite and indefinite) and some pronouns
url_sei <- "https://sei.economia.gov.br"
user_sei <- "usuario aqui"
pwd_sei <- "senha aqui"
org_sei <- "0" ## se tem mais de uma organizacao no login pode ter que mudar aqui.
library(RSelenium)
library(dplyr)
library(rvest)
library(purrr)
library(tictoc)
set.seed(20091975)
## number of stimuli
J <- 6
## draw the stimuli. hold them fixed
x <- sort(runif(J))
sim <- function(
N=100, ## number of individuals
intercept=0,
write('model {
for (i in 1:n.rows) {
y[i] ~ dnorm(y.hat[i], tau.y)
y.hat[i] <- b.0 + b.1 * x[i]
}
b.0 ~ dnorm (0, 1/(sdp^2))
b.1 ~ dnorm (0, 1/(sdp^2))
tau.y ~ dgamma(.0001, .0001)
sigma.y <- pow(tau.y, -(1/2))
plot.heat <- function(tmp,state.map,z,title=NULL,breaks=NULL,cex.legend=1,bw=.2,col.vec=NULL,main=NULL,plot.legend=TRUE, ...) {
tmp@data$zCat <- cut(tmp@data[,z],breaks,include.lowest=TRUE)
cutpoints <- levels(tmp@data$zCat)
if (is.null(col.vec)) col.vec <- heat.colors(length(levels(tmp@data$zCat)))
cutpointsColors <- col.vec
levels(tmp@data$zCat) <- cutpointsColors
cols <- as.character(tmp$zCat)
##cols <- "white"
plot(tmp,border=cols, lwd=bw,axes = FALSE, las = 1,col=as.character(tmp@data$zCat),main="A", ...)
if (!is.null(state.map)) {
## twitter poster for R
## allows delays
##based on http://www.cerebralmastication.com/?p=274
tweet.now <- function(status,userpwd="username:password") {
require(tcltk)
require("RCurl")
opts <- curlOptions(header = FALSE, userpwd = userpwd, netrc = FALSE)
method <- "http://twitter.com/statuses/update.xml?status="
encoded_status <- URLencode(status)
request <- paste(method,encoded_status,sep = "")
@leoniedu
leoniedu / Installing R on dreamhost
Created June 26, 2009 20:23
Installing R on dreamhost
## First do the unix account setup http://wiki.dreamhost.com/Unix_account_setup
cd ${HOME}
# create the first level directories (and log/setup)
mkdir -pv soft run www log log/setup backup data
# create the second level directories within run (our own FHS)
for subdir in bin etc include lib man share
do
mkdir -pv run/${subdir}
done
# symlink so that man pages stay all in the same place