Skip to content

Instantly share code, notes, and snippets.

View daroczig's full-sized avatar

Gergely Daróczi daroczig

View GitHub Profile
@daroczig
daroczig / BCE-MDDA-2018.R
Created November 19, 2018 09:07
BCE // Vállalati Pénzügyi Információs Rendszerek // 2018
## #############################################################################
## PCA demo on image processing
## #############################################################################
download.file('http://bit.ly/nasa-image-pca', 'image.jpg') # mode = »bw«
library(jpeg)
img <- readJPEG('image.jpg')
str(img)
@daroczig
daroczig / print-tracked-tasks.py
Last active November 11, 2018 22:19
Argos script to print currently tracked tasked from Time ++ https://github.com/zagortenay333/timepp__gnome/issues/80
#!/usr/bin/env python
import dbus, dbus.exceptions
import sys
import re
try:
bus = dbus.SessionBus()
timetracker = bus.get_object('org.gnome.Shell', '/timepp/zagortenay333/TimeTracker')
except dbus.exceptions.DBusException as e:
@daroczig
daroczig / Crunch-2018-R-workshop.R
Created November 3, 2018 23:34
Code presented at the R workshop of the Crunch 2018 conference: http://crunchconf.com
## #############################################################################
## intro slides: http://bit.ly/CRUNCH-R-2018
## #############################################################################
## intro to R
## basic operations
1 + 3
3 * 2
@daroczig
daroczig / exercises.R
Last active April 5, 2018 08:24
data.table joins
## generate transactional tables
set.seed(42)
library(data.table)
tx <- data.table(
item = sample(letters[1:3], 10, replace = TRUE),
time = as.POSIXct(as.Date('2016-01-01')) - runif(10) * 36*60^2,
amount = rpois(10, 25))
prices <- data.table(
item = letters[1:3],
date = as.Date('2016-01-01') - 1:2,
@daroczig
daroczig / memisc_and_pander.R
Last active January 24, 2018 19:22
Multiple regression models in a markdown table with memisc and pander
m1 <- lm(mpg ~ hp, data = mtcars)
m2 <- lm(mpg ~ hp + drat, data = mtcars)
m3 <- lm(mpg ~ hp + drat + factor(gear), data = mtcars)
library(pander); library(memisc)
panderOptions('table.alignment.rownames', 'left')
pander(relabel(
mtable(m1, m2, m3,
summary.stats=c('N', 'R-squared', 'F')),
'(Intercept)' = 'Constant',
@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)
## intro slides: http://bit.ly/r-intro-slide
## basic operations
1 + 3
3*2
3^2
## constants
pi
"pi"
@daroczig
daroczig / CRUNCH-2017-R-workshop.R
Created October 19, 2017 12:28
Code presented at the R workshop of the CRUNCH 2017 conference: http://crunchconf.com
## intro slides: http://bit.ly/CRUNCH-R-2017
## basic operations
1 + 3
3*2
3^2
## constants
pi
"pi"
@daroczig
daroczig / data.table.R
Created April 12, 2017 23:11
overlap join demo
# demo transactions data
library(data.table)
txns <- data.table(
rpid = rep(1:3, times = 4),
txid = 1:12,
time = c(10, 10, 10, 11, 15, 20, 12, 16, 25, 13, 21, 30))
## overlap join to see which transactions happened withing 3 time units on the same rpid
## let's define the time periods for the overlap
txns[, start := time - 3]
@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()