Skip to content

Instantly share code, notes, and snippets.

View tomilov's full-sized avatar

Anatoliy V Tomilov tomilov

  • Yandex
  • Yekaterinburg
View GitHub Profile
@tomilov
tomilov / ddp_ssp.cpp
Last active November 13, 2019 17:44
dynamic dynamic programming for subset sum problem
#include <iostream>
#include <algorithm>
#include <cassert>
struct pair
{
int term;
int sum;
pair operator + (int x)
@tomilov
tomilov / crc32c.h
Last active January 30, 2018 16:45
CRC-32C
#pragma once
#include <cstdint>
#include <x86intrin.h>
inline
std::uint32_t crc32c(const void * input, std::size_t size, std::uint32_t result = ~0)
{
auto i8 = static_cast< const std::uint8_t * >(input);
@tomilov
tomilov / ssh-telegram.sh
Created September 29, 2017 19:51 — forked from matriphe/ssh-telegram.sh
Bash Script to notify via Telegram Bot API when user log in SSH
# save it as /etc/profile.d/ssh-telegram.sh
# use jq to parse JSON from ipinfo.io
# get jq from here http://stedolan.github.io/jq/
USERID="<target_user_id>"
KEY="<bot_private_key>"
TIMEOUT="10"
URL="https://api.telegram.org/bot$KEY/sendMessage"
DATE_EXEC="$(date "+%d %b %Y %H:%M")"
TMPFILE='/tmp/ipinfo-$DATE_EXEC.txt'
if [ -n "$SSH_CLIENT" ]; then
@tomilov
tomilov / stream.js
Created April 23, 2017 18:27 — forked from padenot/stream.js
How to serve media on node.js
var http = require('http');
var path = require('path');
var fs = require('fs');
var AUDIOFILE = "./audio.ogg";
function serveWithRanges(request, response, content) {
var range = request.headers.range;
var total = content.length;
var parts = range.replace(/bytes=/, "").split("-");
#include <boost/preprocessor/seq/for_each_i.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <utility>
#include <cstddef>
namespace details
{
#include <type_traits>
#include <utility>
template< std::size_t index, typename type >
struct ref { type & value; };
template< std::size_t index, typename type >
type && get(ref< index, type > const & r)
{
return std::forward< type >(r.value);
@tomilov
tomilov / gcc.cpp
Created November 12, 2016 22:09
array to template arguments
#include <type_traits>
#include <utility>
#include <iterator>
#include <typeinfo>
#include <memory>
#include <mutex>
#include <string>
#include <cxxabi.h>
@tomilov
tomilov / ratio.cpp
Last active October 25, 2016 08:13
#include <numeric>
#include <cassert>
class ratio
{
std::size_t n, d; // numerator, denominator
void
#include <type_traits>
#include <utility>
#include <tuple>
struct filler { template< typename type > operator type (); };
template< typename aggregate,
typename index_sequence = std::index_sequence<>,
typename = void >
struct aggregate_arity
#include <utility>
template< std::size_t I, typename F >
struct wrapper { F f; };
template< std::size_t I, typename F >
constexpr
F &
get(wrapper< I, F > * sg) noexcept
{