Skip to content

Instantly share code, notes, and snippets.

@artemklevtsov
artemklevtsov / raw_char.cpp
Last active September 13, 2020 07:43
charToRaw and charToRaw Rcpp implementation.
// [[Rcpp::plugins(cpp17)]]
#include <Rcpp.h>
// [[Rcpp::export(rng = false)]]
Rcpp::RawVector Cpp_charToRaw1(const std::string& s) {
Rcpp::RawVector res(s.begin(), s.end());
return res;
}
// [[Rcpp::export(rng = false)]]
#include <sstream>
#include <string>
#include <unordered_map>
#include <Rcpp.h>
using map = std::unordered_map<std::string, std::string>;
static inline void trim(std::string& s) {
s.erase(std::find_if_not(s.rbegin(), s.rend(), ::isspace).base(), s.end());
s.erase(s.begin(), std::find_if_not(s.begin(), s.end(), ::isspace));
@artemklevtsov
artemklevtsov / curl-ftp.R
Last active July 5, 2019 17:47
R curl FTP example
# install.packages("https://github.com/jeroen/curl/archive/master.tar.gz", repos = NULL)
ftp_list_files <- function(url, user = NULL, password = NULL) {
checkmate::assert_string(url, pattern = "ftp://")
checkmate::assert_string(user, null.ok = TRUE)
checkmate::assert_string(password, null.ok = TRUE)
h <- curl::new_handle()
curl::handle_setopt(
handle = h,
@artemklevtsov
artemklevtsov / RestRserveEndpoint.R
Last active July 11, 2019 04:22
Реализация класса для шаблонов URL
RestRserveEndpoint <- R6::R6Class(
classname = "RestRserveEndpoint",
public = list(
path = NULL,
method = NULL,
regex = NULL,
vars = NULL,
initialize = function(path, prefix = FALSE, pattern = FALSE) {
private$assert_path(path)
checkmate::assert_flag(prefix)
@artemklevtsov
artemklevtsov / inn.R
Last active June 26, 2019 03:30
Получение ИНН физического лица на сайте ФНС
#' @title Запрос ИНН физического лица
#'
#' @param first_name (Строка) Имя.
#' @param last_name (Строка) Фамилияю
#' @param middle_name (Строка) Отчество.
#' @param birth_date (Дата) Дата рождения.
#' @param passport_series (Строка) Серия паспорта.
#' @param passport_number (Строка) Номер паспорта.
#'
#' @examples
@artemklevtsov
artemklevtsov / ffmpeg-livestream-to-streaming-sites-vaapi-nvenc.md
Created February 10, 2019 07:42 — forked from Brainiarc7/ffmpeg-livestream-to-streaming-sites-vaapi-nvenc.md
ffmpeg livestreaming to youtube via Nvidia's NVENC and Intel's VAAPI on supported hardware

Streaming your Linux desktop to Youtube and Twitch via Nvidia's NVENC and VAAPI:

Considerations to take when live streaming:

The following best practice observations apply when using a hardware-based encoder for live streaming to any platform:

  1. Compute the optimal buffer size (-bufsize:v) for hardware-based encoders as shown:

bufsize=4(target bitrate/frame rate)

@artemklevtsov
artemklevtsov / gist:85545e14405d7a39cded02747eeaf899
Created January 22, 2019 14:01 — forked from mtigas/gist:952344
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
@artemklevtsov
artemklevtsov / cv.cpp
Last active November 25, 2018 08:29
Quick, Draw! Doodle Recognition Challenge raw data processing
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::plugins(opencv)]]
// [[Rcpp::depends(rapidjsonr)]]
// [[Rcpp::depends(RcppThread)]]
#include <rapidjson/document.h>
#include <opencv2/opencv.hpp>
#include <Rcpp.h>
#include <RcppThread.h>
library(data.table)
library(ROCR)
library(ggplot2)
f_plot <- function(predictions, labels) {
if (is.list(predictions) && is.atomic(labels))
labels <- rep.int(list(labels), length(predictions))
p <- prediction(predictions, labels)
# Labels
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
using namespace Rcpp;
template <int RTYPE>
Vector<RTYPE> na_locf_impl(Vector<RTYPE> x) {
std::size_t n = x.size();
auto v = x[0];