Skip to content

Instantly share code, notes, and snippets.

View daroczig's full-sized avatar

Gergely Daróczi daroczig

View GitHub Profile

Keybase proof

I hereby claim:

  • I am daroczig on github.
  • I am daroczig (https://keybase.io/daroczig) on keybase.
  • I have a public key is ASBYP5QGYjtBrURgkEZJXoJrs_sWW8u-ENKAFO36yUGQDwo

To claim this, I am signing this object:

@daroczig
daroczig / Migrants-captured-in-Hungary.png
Last active September 23, 2015 14:22
Download and parse public data on the number of "catched" refugees in Hungary 2015
Migrants-captured-in-Hungary.png
@daroczig
daroczig / guess.R
Created September 9, 2015 20:44
Guess file delimiter, quote and decimal mark in text files
#' Guess a text data file's parameters
#' @param file filename
#' @return list of \code{sep}, \code{quote}, \code{dec}, \code{header},\code{fileEncoding}
#' @export
import.text.guess <- function(file) {
## check encoding -> encoding
encoding <- sub('.*charset=', '', system(sprintf('file -bi %s', shQuote(file)), intern = TRUE))
if (encoding %in% c('???', 'unknown-8bit')) {
warning('Could not identify encoding!')
@daroczig
daroczig / meetup-members.R
Last active December 19, 2017 15:25
Fetch the number of R User Group members around the world
library(XML)
html <- htmlParse(readLines('https://www.meetup.com/topics/r-project-for-statistical-computing/all/'))
names <- xpathSApply(html, '//li[@class="gridList-item"]/a/span', xmlValue)
attrs <- xpathSApply(html, '//li[@class="gridList-item"]/span[@class="text--secondary text--small chunk"]', xmlValue)
attrs <- gsub('\\n|\\t', '', attrs)
users <- as.numeric(gsub(',', '', sub('^([0-9,]*) .*', '\\1', attrs)))
geo <- sub('.* \\| ', '', attrs)
data.frame(name = names, location, members)
@daroczig
daroczig / impala.R
Last active February 2, 2017 17:10
Connect and query Imapala via SSH and Impala-shell from R
#' Connect and query Imapala via SSH and Impala-shell
#' @param query SQL query to run
#' @param host server hostname or IP
#' @param log enable or disable logging of debug/trace messages
#' @return data.table object
#' @export
query_impala <- function(query, host = 'localhost', log = require(futile.logger)) {
## measure time of query
timer <- proc.time()
@daroczig
daroczig / server.R
Created June 29, 2015 11:32
Markdown preview via shiny, pandoc and rmarkdown
library(shiny)
library(rmarkdown)
shinyServer(function(input, output) {
output$html = reactive({
t <- tempfile()
cat(input$markdown, file = t)
@daroczig
daroczig / meme.jpg
Last active August 29, 2015 14:23
Markdown preview via shiny, pandoc and pander
meme.jpg
@daroczig
daroczig / Dockerfile
Created May 14, 2015 19:53
R with Java Docker container based on https://github.com/rocker-org/rocker
## Start with the official rocker image (lightweight Debian)
FROM rocker/r-base:latest
MAINTAINER Gergely Daroczi <gergely.daroczi@card.com>
## Install Java
RUN echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" \
| tee /etc/apt/sources.list.d/webupd8team-java.list \
&& echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" \
| tee -a /etc/apt/sources.list.d/webupd8team-java.list \
@daroczig
daroczig / commands_to_run
Last active August 29, 2015 14:07
evals demo
library(pander)
evals(readLines('demo.R'))
> dim(m)
[1] 32400 32400
> sum(m) / prod(dim(m))
[1] 0.0007337982
> table(rowSums(m))
0 16 22 26 35 38 41 46
15549 96 30 29 28 27 26 16615
> table(colSums(m))