Skip to content

Instantly share code, notes, and snippets.

#include <Rcpp.h>
#include <boost/sort/spreadsort/spreadsort.hpp>
using namespace Rcpp;
using namespace boost::sort::spreadsort;
template <int RTYPE>
Vector<RTYPE> sort_impl(const Vector<RTYPE> & x, bool decreasing = false) {
Vector<RTYPE> res = no_init(x.size());
std::copy(x.begin(), x.end(), res.begin());
@artemklevtsov
artemklevtsov / ip-api.R
Last active January 27, 2017 17:52
Геолокация по IP адресу
#' @title Geolocate IP Addresses Through ip-api.com
#' @description
#' \code{geolocate} consumes a vector of IP addresses and geolocates them via
#' \href{http://ip-api.com}{ip-api.com}.
#' @param ip a character vector of IP addresses.
#' @param lang a string to specify an output localisation language.
#' Allowed values: en, de, es, pt-BR, fr, ja, zh-CN, ru.
#' @param fields a string to specify which fields to return.
#' @param delay a logical to whether or not to delay each request by 400ms.
#' ip-api.com has a maximum threshold of 150 requests a minute. Disable it for
#!/usr/bin/env python3
# Импорт библиотек
import sys
from urllib.request import Request, urlopen
from urllib.error import HTTPError
from html.parser import HTMLParser
import json
class Parser(HTMLParser):
@artemklevtsov
artemklevtsov / Makefile
Last active September 14, 2016 17:18
Шаблоны для презентаций в pandoc
PANDOC_ARGS = --slide-level 2 --latex-engine=xelatex
MD_FILES = $(wildcard *.md)
PDF_FILES = $(patsubst %.md, %.pdf, $(MD_FILES))
TEX_FILES = $(patsubst %.md, %.tex, $(MD_FILES))
all: pdf
pdf: $(PDF_FILES)
tex: $(TEX_FILES)
@artemklevtsov
artemklevtsov / Makefile
Last active August 19, 2016 10:36
Makefile for R packages
PKG_NAME = $(shell grep '^Package: ' DESCRIPTION | cut -d ':' -d ' ' -f 2)
PKG_VER = $(shell grep '^Version: ' DESCRIPTION | cut -d ':' -d ' ' -f 2)
PKG_TAR = $(PKG_NAME)_$(PKG_VER).tar.gz
BUILD_ARGS = --no-build-vignettes
CHECK_ARGS = --as-cran --no-manual --no-vignettes --no-build-vignettes
all: install doc check clean
install:
R --vanilla CMD INSTALL --no-test-load .
@artemklevtsov
artemklevtsov / .gitlab-ci.yml
Last active January 12, 2024 04:14
Testing R package with GitLab CI (with code coverage)
variables:
CODECOV_TOKEN: "CODECOV_TOKEN_STRING"
_R_CHECK_CRAN_INCOMING_: "false"
_R_CHECK_FORCE_SUGGESTS_: "true"
APT_PKGS: "libcurl4-openssl-dev libssh2-1-dev libssl-dev libxml2-dev zlib1g-dev git"
before_script:
- apt-get update
- apt-get install -y --no-install-recommends ${APT_PKGS}
- apt-get install -y --no-install-recommends qpdf pandoc pandoc-citeproc
#!/usr/bin/env python
from sys import argv
from random import choice
def gen_letters(nrows = 60, ncols = 40):
letters = "АБВГДЕЖЗИКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯ"
return "\n".join(" ".join(choice(letters) for i in range(ncols)) for j in range(nrows))
def gen_numbers(nrows = 60, ncols = 40):
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
IntegerVector findInterval2(const NumericVector& x, const NumericVector& breaks) {
std::size_t n = x.size();
IntegerVector out = no_init(n);
@artemklevtsov
artemklevtsov / shuffle.cpp
Last active August 13, 2016 19:18
Fisher-Yates Shuffle for the Rcpp vector
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
using namespace Rcpp;
template <int RTYPE>
Vector<RTYPE> shuffle_impl(const Vector<RTYPE>& x) {
Vector<RTYPE> res(x); // make copy
auto first = res.begin(), last = res.end();
@artemklevtsov
artemklevtsov / rep.cpp
Last active December 4, 2016 13:06
rep functions family implementation
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]
template <int RTYPE>
Vector<RTYPE> rep_each_impl(const Vector<RTYPE>& x, std::size_t each) {
std::size_t n = x.size();
Vector<RTYPE> res = no_init(n * each);
auto begin = res.begin();