Skip to content

Instantly share code, notes, and snippets.

Petr Simecek simecek

Block or report user

Report or block simecek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@simecek
simecek / netiquette.r
Created Oct 25, 2011
Email Netiquette
View netiquette.r
count.google.hits <- function(query) {
# call Google Search and extract the number of hits
url <- paste('http://www.google.com/search?q=', query, sep="")
tmp <- readLines(url, warn=FALSE)
writeLines(tmp, "c:\\temp\\pokus.html")
pattern <- ".*<div id=resultStats>[A-Za-z ]*([0-9 ,]*) results<nobr> \\([0-9.]* seconds\\).*"
count.line <- grep(pattern,tmp)[1]
hits <- sub(pattern, "\\1", tmp[[count.line]])
@simecek
simecek / pim.R
Created Nov 23, 2011
Prague Half Marathon 2010
View pim.R
library(xlsReadWrite)
library(MASS)
### DATA DOWNLOAD
dir.name <- tempdir()
url2010 <- "http://www.praguemarathon.com/images/stories/articles/files/HM2010/HM2010_eng.xls"
file <- paste(dir.name, "2010.xls", sep="\\")
View gist:1587954
function SearchEmail() {
var mySheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var EmailName = Browser.inputBox("Search", "Type from:email@address.cz", Browser.Buttons.OK_CANCEL);
var maxthreads = 250;
var searchedThreads= GmailApp.search("from:(<" + EmailName + ">)", 0, maxthreads);
var regExp = new RegExp(".*<" + EmailName + ">$");
var counter = 1;
for(var i in searchedThreads){
var messages = searchedThreads[i].getMessages();
@simecek
simecek / plotting.R
Created Jan 10, 2012
Make the plot of data mined by Google Apps Script
View plotting.R
data <- read.csv("http://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AnhE_6FIbbVWdFNxeS1ESWtvSUk5WE5KcnBwVWVqckE&output=csv", header=FALSE, skip=1, as.is=TRUE)
sent <- data.frame(Time=strptime(data[,1], "%H:%M:%S"))
library(ggplot2)
theme_update(panel.background = theme_rect(fill = "grey90", colour = "black"))
xstart <- strptime("01:00:00", "%H:%M:%S")
xend <- strptime("23:00:00", "%H:%M:%S")
ggplot(sent, aes(Time)) + geom_density(fill="grey50", adjust=0.5) + xlim(xstart, xend)
@simecek
simecek / facebook_friendship1.r
Created Jan 18, 2012
Facebook Friendship Graph
View facebook_friendship1.r
# the code uses 'facebook' function from the previous gist (https://gist.github.com/1634662) or
# see the original http://romainfrancois.blog.free.fr/index.php?post/2012/01/15/Crawling-facebook-with-R
# scrape the list of friends
friends <- facebook( path="me/friends" , access_token=access_token)
# extract Facebook IDs
friends.id <- sapply(friends$data, function(x) x$id)
# extract names
friends.name <- sapply(friends$data, function(x) iconv(x$name,"UTF-8","ASCII//TRANSLIT"))
# short names to initials
@simecek
simecek / facebook_friendship2.r
Created Jan 18, 2012
Facebook Friendship Graph Continued
View facebook_friendship2.r
require(pixmap)
# download small profile picture of each friend
dir.create("photos")
for (i in 1:length(friends.id))
download.file(paste("http://graph.facebook.com", friends.id[i], "picture", sep="/"),
destfile=paste("photos/",friends.id[i],".jpg",sep=""))
system('for i in `ls photos/*.jpg`; do j=${i%.*}; convert $j.jpg $j.pnm; done', wait=TRUE)
# customized node plotting function
View facebook_mining.r
# go to 'https://developers.facebook.com/tools/explorer' to get your access token
access_token <- "******************* INPUT YOUR ACCESS TOKEN ******************************"
require(RCurl)
require(rjson)
# Facebook json function copied from original (Romain Francois) post
facebook <- function( path = "me", access_token, options){
if( !missing(options) ){
options <- sprintf( "?%s", paste( names(options), "=", unlist(options), collapse = "&", sep = "" ) )
View get.dropbox.folder.r
get.dropbox.folder <- function() {
if (!require(RCurl)) stop ("You need to install RCurl package.")
if (Sys.info()["sysname"]!="Windows") stop("Currently, 'get.dropbox.folder' works for Windows only. Sorry.")
db.file <- paste(Sys.getenv('APPDATA'), '\\Dropbox\\host.db', sep='')
base64coded <- readLines(db.file, warn=FALSE)[2]
base64(base64coded, encode=FALSE)
}
View s3.r
library(httr)
library(digest)
library(XML)
s3_request <- function(verb, bucket, path = "/", query = NULL,
content = NULL, date = NULL) {
list(
verb = verb,
bucket = bucket,
path = path,
@simecek
simecek / IMGC14_twitter_analysis.R
Last active Aug 29, 2015
Analysis of #IMGC14 tweets
View IMGC14_twitter_analysis.R
library(twitteR)
library(tm)
library(wordcloud)
library(RColorBrewer)
library(dplyr)
library(ggplot2)
# load tweets
download.file("ftp://ftp.jax.org/petrs/other/IMGC14.rds", destfile = "IMGC14_tweets.rds", mode="wb")
tweet <- readRDS("IMGC14_tweets.rds")
You can’t perform that action at this time.