Skip to content

Instantly share code, notes, and snippets.

@hpiwowar
hpiwowar / bibtex_to_csv.py
Created July 1, 2011 22:20
For exporting bibtex info into csv for running stats
#!/usr/bin/env python
# Initially written by Heather Piwowar, June 2011
# Public domain: have at it!
# For exporting bibtex info into csv for running stats
import csv
import re
from pybtex.database.input import bibtex as bibtex_in
from pybtex.database.output import bibtex as bibtex_out
from operator import itemgetter, attrgetter
@epijim
epijim / FacebookFromR.r
Last active November 20, 2023 23:29
scrape facebook from R. Based off
###############################################################################################
## ##
## Setup ##
## ##
###############################################################################################
# install.packages("Rfacebook") # from CRAN
# install.packages("Rook") # from CRAN
# install.packages("igraph") # from CRAN
@jeroen
jeroen / cheerio.R
Created January 13, 2015 00:01
V8 cheerio rvest example
# Proof of concept of using V8 to parse HTML in R
# Example taken from rvest readme
# Jeroen Ooms, 2015
library(V8)
stopifnot(packageVersion("V8") >= "0.4")
# Get Document
html <- paste(readLines("http://www.imdb.com/title/tt1490017/"), collapse="\n")
@JustDevZero
JustDevZero / provinces_es.csv
Last active March 3, 2026 09:00
CSV con las provincias de españa, sus respectivos códigos y prefijos | CSV with spain provinces, and their respectives codes and prefixes
code postal_code name phone_code iso2
VI 01 Álava 945 ES
AB 02 Albacete 967 ES
A 03 Alacant 950 ES
AL 04 Almería 920 ES
AV 05 Ávila 924 ES
BA 06 Badajoz 924 ES
PM 07 Illes Balears 971 ES
B 08 Barcelona 93 ES
BU 09 Burgos 947 ES
@retrography
retrography / json2csv.R
Last active February 26, 2021 23:09
JSON to CSV convertor. Uses `jsonlite` R package, flattens all the hierarchical structure and converts all remaining lists/arrays into strings.
#!/usr/bin/Rscript
if (!require(jsonlite, quietly = TRUE, warn.conflicts = FALSE)) {
stop("This program requires the `jsonlite` package. Please install it by running `install.packages('jsonlite')` in R and then try again.")
}
args <- commandArgs(trailingOnly = TRUE)
if (length(args) == 0) {
input <- readLines(file("stdin"))
@mkearney
mkearney / search_tweets-ex-txlege.R
Last active November 16, 2019 17:41
Search tweets example using #txlege tweets
library(rtweet)
## number of iterations
n <- 5
## to do a certain task (e.g., searching for tweets on a topic),
## twitter policy says you should use one token
## so select one token
token <- get_tokens()
if (!"Token" %in% class(token)) {
@macloo
macloo / twitter_bio_compiler_for_list.py
Last active October 20, 2022 22:27
Scrape members from a Twitter list and then get their bios, locations, etc.
#!/usr/bin/env python
# encoding: utf-8
"""
python 2.x
Scrape members from a Twitter list and then get their bios, locations, etc.
Based on
https://github.com/lamthuyvo/social-media-data-scripts/blob/master/scripts/twitter_bio_info_compiler.py
and
https://github.com/kylemanna/social-utils/blob/master/twitter/list-follow.py
@almogsi
almogsi / passive.R
Last active August 19, 2019 21:55
This code snippet takes a vector of strings and calculates the percentage of passive voice in the input text. It uses Stanford NLP tool and coreNLP for R.
library(rJava)
library(coreNLP)
initCoreNLP()
#in this case, 'test' is a data frame with a col named 'text'
for (i in 1:dim(test)[1]) {
cat(paste0(i / dim(test)[1] * 100, '% completed'))
ann <- annotateString(paste(test$text[i]), format = c("obj"), outputFile = NA, includeXSL = FALSE)
gd <- getDependency(ann)
@dfbarrero
dfbarrero / density.R
Created November 22, 2017 18:23
R script that uses Lattice to plot a Choropleth map.
#!/usr/bin/Rscript --vanilla
library(sp)
#library(RColorBrewer)
colorPalette <- colorRampPalette(c("white", "orange"))(32)
spain <- readRDS("ESP_adm1.rds")
# Datos de Informe Anual del Sector TIC y de los Contenidos en España 2016. ONTSI
library(tidyverse)
buzzes <- read_csv("~/Desktop/regs analysis/all_buzzes.csv")
tossups_heard <- read_csv("~/Desktop/regs analysis/tossups_heard.csv") %>%
filter(!is.na(Packet)) %>%
group_by(Packet) %>%
summarize(Heard = max(Heard))
tossups <- buzzes %>%