Skip to content

Instantly share code, notes, and snippets.

#include <vector>
#include <list>
using namespace std;
// N - длина стержня, costs[i] - стоимость отрезка длины i+1
vector<size_t> GetCuts(size_t N, const vector<int>& costs) {
// элемент односвязного списка
struct Node {
size_t cutlength;
list<Node>::iterator next;
@slavanap
slavanap / chunks2lines.py
Last active June 15, 2017 13:54
Chunks to Lines in Python 2.7
def ChunksToLines(reader):
history = []
for chunk in reader:
lines = chunk.splitlines()
if chunk[-1] == '\n':
lines.append('')
elif len(lines) == 1:
history.append(lines[0])
continue
history.append(lines[0])
@slavanap
slavanap / copy-docker-container-volumes.sh
Last active April 13, 2018 07:25
Copy contents of CONTAINER volumes to DEST_FOLDER
# Copy contents of CONTAINER volumes to DEST_FOLDER
# usage: volcp CONTAINER DEST_FOLDER
volcp() (
set -e
if [[ -z "$2" ]]; then
echo "ERROR: Destination folder must be specified as second argument" >&2
exit 1
fi
echo " To mount volumes please run:"
echo "docker run \\"
@slavanap
slavanap / r.py
Last active May 9, 2018 22:32
Add RKN rules to reroute traffic
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import sys
from ipaddress import IPv4Network
iterbytes = lambda b: (b[i:i+1] for i in range(len(b)))
@slavanap
slavanap / decimal.cs
Created June 2, 2018 09:08
Tests for System.Decimal.GetHashCode()
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
@slavanap
slavanap / opus_psrn.py
Last active June 16, 2018 19:41
Compute libopus and libvorbis PSNR
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import scipy.io.wavfile
import scipy.signal
import subprocess
import tempfile
ffmpeg = "avconv"
<VirtualHost *:80>
Alias "/.well-known" "/var/www/html/.well-known"
# redirect other paths to https
RewriteEngine On
RewriteCond %{REQUEST_URI} !/.well-known/.*
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/ [R,L]
</VirtualHost>
<VirtualHost *:443>
@slavanap
slavanap / test.lst
Created November 3, 2018 14:55
MASM_bug_demo listing
Microsoft (R) Macro Assembler Version 14.15.26732.1 11/03/18 17:47:56
test.asm Page 1 - 1
.386
.MODEL flat, stdcall
OPTION casemap: none
00000000 .CONST
00000000 2A label1 DB 42
template<typename ... TArgs>
void prn() {
((cout << typeid(TArgs).name() << endl), ...);
};
template<typename Function>
struct f;
template<typename TReturn, typename... TArgs>
@slavanap
slavanap / DistributedCacheUpdater.cs
Last active May 11, 2019 20:41
Populate cache from single thread.
/*
class UsageSample {
public DistributedCacheUpdater _cache;
async Task<JObject> GetResponse(HttpRequestMessage httpRequest, DistributedCacheEntryOptions cacheOptions, CancellationToken ct) {
using (var proxy = await DistributedCacheUpdater.RequestAsync(_cache, httpRequest.RequestUri.ToString(), ct)) {
string responseData;
if (proxy.Value == null) {
_metrics.Measure.Meter.Mark(_cacheHits, "nohit");
using (var httpResponse = await _client.SendAsync(httpRequest, HttpCompletionOption.ResponseContentRead, ct)) {