Skip to content

Instantly share code, notes, and snippets.

View czeildi's full-sized avatar
🎲

Ildikó Czeller czeildi

🎲
View GitHub Profile
@czeildi
czeildi / cumulative_uniqueN.R
Created June 11, 2017 10:28
compute cumulative unique N with R's data.table package
dt <- data.table(x = c(4,4,2,5,4,2,3))
dt[, g := .GRP, by = x]
dt[, cumuniquen := cummax(g)]
@czeildi
czeildi / ts_aggregation.R
Created June 11, 2017 11:16
time series aggregation by different units in R using xts
library("xts")
dt <- data.table(
day = seq.Date(as.Date('2016-07-01'), by = 'day', length.out = 180),
x = 1:180,
y = 1001:1180
)
ts_data <- as.xts(dt)
@czeildi
czeildi / dt_new_col.R
Created June 25, 2017 11:05
define new column from list of columns in data.table rowwise
# dt is a data.table with id_cols and value_cols
# we want rows where any of the value cols is not NA regardless of the
# values of the id_cols
dt[, to_keep := purrr::pmap_lgl(
purrr::map_df(
dt[, .SD, .SDcols = value_cols],
~ !is.na(.x)
),
any
@czeildi
czeildi / tennis_1_refactored.js
Created June 27, 2017 19:51
tennis refactoring kata solution
var TennisGame1 = function(player1Name, player2Name) {
this.scores = [
0,
0
];
this.players = [
player1Name,
player2Name
];
@czeildi
czeildi / code_cov_for_project.R
Last active August 22, 2017 08:24
code coverage with covr for a project which is not an R package
# open Rproj with packrat
# restart R session
library("testthat")
source("libraries.R")
packrat::with_extlib(
c("rex", "covr", "DT"), {
library("rex")
library("covr")
@czeildi
czeildi / dojo.py
Created August 22, 2017 13:21
python dojo skeleton with unittest
class Dojo:
def __init__(self, input):
self.input = input
def calculate(self):
return 42
@czeildi
czeildi / week_numbers.R
Created August 28, 2017 08:46
how R handles week starts: Sunday vs Monday start
library("lubridate")
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> date
a_sunday <- as.Date("2017-08-27")
# floor_date rounds to Sunday:
@czeildi
czeildi / download_tutorial.md
Last active September 1, 2017 17:42
fájlok letöltése githubról git nélkül

Ha nincs git (verziókövető rendszer) a számítógépeden, de mégis szeretnél fájlokat letölteni egy github repositoryból, a következő lehetőségeid vannak:

A legegyszerűbb talán a kezdőoldalon zip-ként az egész projektet letölteni, majd ezt a gépeden kicsomagolni. Így garantált, hogy megmarad a mappastruktúra, és minden fájl típusa.

Fontos, hogy egy-egy fájl vagy mappa linkjére jobb klikk, mentés esetén nem a fájl, hanem az egész weboldal fog letöltődni, ami tipikusan nem az, amit szeretnénk.

Ha egyesével szeretnél fájlokat letölteni, fájltípustól függően kicsit más felülettel fogsz találkozni, miután rákattintottál a fájl linkjére. Ha nem szöveg alapú fájlról van szó (md, csv, R, js etc) akkor egyszerűbb a dolgod, fogsz látni egy download gombot.

@czeildi
czeildi / cs_check.R
Created September 17, 2017 16:16
codeship basic check
check_results <- devtools::check()
print(check_results)
if (length(check_results$errors) + length(check_results$warnings) + length(check_results$notes) >= 1) {
stop('error, warning or note found')
}
@czeildi
czeildi / ggplot_theme.R
Created October 2, 2017 15:14
custom ggplot2 theme code for BURN meetup
# setup: example data
library(ggplot2)
library(data.table)
dt <- data.table(
period = c("before", "after", "before", "after"),
segment = c("treatment", "treatment", "control", "control"),
revenue = c(80, 85, 78, 79)
)