Skip to content

Instantly share code, notes, and snippets.

@Ironholds
Ironholds / flask.R
Created October 1, 2014 14:33
no, not the python framework
if(k < 2){
drink_to_forget()
}
SELECT regexp_extract(uri_path, '/((\\d+px-)?[^/]+)$', 1) as uri_file
FROM wmf_raw.webrequest
WHERE year = 2014 AND month = 09 AND day = 23 AND
hour = 07 AND webrequest_source='upload' LIMIT 5;
@Ironholds
Ironholds / timings.cpp
Created October 7, 2014 16:07
timings
//R
min lq mean
200422 201139.5 202649.46
15 18.0 33.01
median uq max neval
201427 201824 258190 100
37 51 56 100
//C++
min lq mean median
//Includes/namespaces
#include <Rcpp.h>
using namespace Rcpp;
// Recursive session counting function
// [[Rcpp::export]]
int session_count(NumericVector x, int local_minimum) {
//Create output object
int count;
intertimes <- function(x, local_minimum){
return(length(x[x > local_minimum]) + 1)
}
test Freq
1 Cable 416932
2 Corporate 13848
3 Dial-up 77302
4 Invalid 17842
5 Unknown 71175
@Ironholds
Ironholds / breakdowns.R
Created October 8, 2014 22:34
Timing breakdowns
#Intertime computation timings, for a test vector of 3.4k elements.
#Original C++ implementation
expr min lq mean median uq max neval
{ test <- intertime(test_vec) } 3.982 4.25 7.805621 4.3405 4.564 687.78 1000
#C++ implementation with RCpp's "diff()" - syntactic sugar around adjacent_difference
expr min lq mean median uq max neval
{ test <- intertime2(test_vec) } 4.181 4.354 9.668984 4.437 4.696 823 1000
> z <- c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE)
>
> rle(z)
Run Length Encoding
lengths: int [1:5] 2 2 1 1 3
values : logi [1:5] TRUE FALSE TRUE FALSE TRUE
@Ironholds
Ironholds / with_tz_test.R
Created October 20, 2014 21:18
with_tz and data.table
#For our test object, we have x, a data.table
timestamp tz order
1: 20140907142430 Europe/Warsaw 1
2: 20141005162245 Europe/Paris 2
3: 20140908142859 Europe/Rome 3
4: 20140903093741 Asia/Yerevan 4
5: 20140805102142 America/Sao_Paulo 5
6: 20140905142222 Europe/Brussels 6
7: 20140819225906 Europe/Rome 7
8: 20140811190410 Europe/London 8
@Ironholds
Ironholds / timestamps.R
Created October 22, 2014 20:30
timestamps
x <- x[, j = {
#Copy object
copy.dt <- copy(.SD)
#Convert timestamps
timestamps <- mw_strptime(copy.dt$timestamp)
#Extract timestamps, convert as appropriate.
copy.dt$original_timestamp <- as.character(timestamps)