Skip to content

Instantly share code, notes, and snippets.

View PolarNick239's full-sized avatar

Nikolai Poliarnyi PolarNick239

View GitHub Profile
# http://codeforces.com/contest/769/problem/D
import time
import numpy as np
import pyopencl as cl
runs_number = 50
n, k = [int(x) for x in input("n k: ").split()]
values = input("Values (or empty line for random values): ")
if len(values) == 0:
np.random.seed(239)
@PolarNick239
PolarNick239 / memavailable.cpp
Last active March 6, 2017 17:42
Function to measure available memory on Linux, can be easily adopted to get any value from /proc/meminfo
#include <string.h>
#include <cstdlib>
bool get_memavailable_from_meminfo(size_t &memavailable)
{
const int LINE_LEN = 512;
char str[LINE_LEN];
FILE *fp = fopen("/proc/meminfo","rt");
if (fp == NULL) {
--- a/PC/python.manifest
+++ b/PC/python.manifest
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
- <trustInfo>
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
@PolarNick239
PolarNick239 / blocking_queue.h
Last active September 11, 2022 12:30
C++ concurrent blocking queue with limited size (based on boost condition_variable)
#include <queue>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
// Based on https://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
template<typename Data>
class BlockingQueue {
private:
std::queue<Data> queue;
mutable boost::mutex queue_mutex;
@PolarNick239
PolarNick239 / printerbot.py
Created August 7, 2017 20:58
Telegram bot for printer (Linux)
import os
import pathlib
import logging
from telegram.ext import Updater
from telegram.ext import Filters
from telegram.ext import CommandHandler
from telegram.ext import MessageHandler
# This is the Telegram Bot that prints all input documents. It can print pdf and txt files.
# Before sending files for printing user must enter the password by command "/auth <password>".
@PolarNick239
PolarNick239 / stitch_pdf.py
Last active August 30, 2017 10:25
PDF from images. Script downscales all jpg images and then merges them into pdfs with pdftk.
#!/usr/bin/python3.5
import os
import glob
import pathlib
from pathlib import Path
# How to use:
# Run in directory with folders named from 1 and up to 99. Each folder should contain *.JPG files.
# Script will downscale all files that are not yet downscaled to "downscaled" subdirectory and stitch to multiple pdfs: pdf per folder + single full pdf.
# Example of input directories:
@PolarNick239
PolarNick239 / benchmark.py
Last active June 18, 2019 11:39
Metashape benchmark for Dense Cloud and alignment
import Metashape
# wget https://www.dropbox.com/s/hh5yg0fmpr4bpn3/benchmarking_1.3.zip
# unzip benchmarking_1.3.zip
project = "benchmark2.psz"
Metashape.app.gpu_mask = (2 ** 16) - 1
Metashape.app.cpu_enable = False
Metashape.app.document.open(project, read_only=True)
@PolarNick239
PolarNick239 / ps_install_ocv.sh
Last active March 27, 2018 00:24
OpenCV compilation script for python bundled with PhotoScan. Should work with any other Python (and with virtualenv). Tested on Ubuntu 16.04
# Configure path to photoscan:
PHOTOSCAN_PATH=<.../photoscan-pro>
PYTHON_PATH=${PHOTOSCAN_PATH}/python
OPENCV_VERSION=3.4.0
INSTALLATION_PATH=/opt/opencv-${OPENCV_VERSION}
sudo mkdir -p ${INSTALLATION_PATH}
# Install numpy (OpenCV requires it)
CPPFLAGS=-I${PYTHON_PATH}/include/python3.5m LDFLAGS=-L${PYTHON_PATH}/lib ${PYTHON_PATH}/bin/python3.5 -m pip install numpy==1.08
const int triangles[256][5*3+1] = {{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},{ 0, 4, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 5, 0, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 8, 9, 5, 8, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 1, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 0, 4, 8, 1, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 9, 11, 1, 9, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 8, 9, 11, 8, 11, 1, 8, 1, 4, -1, -1, -1, -1, -1, -1, -1},
{ 4, 1, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 10, 8, 0, 10, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 5, 0, 9, 4, 1, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
@PolarNick239
PolarNick239 / opencl_clion_defines.cpp
Created July 19, 2018 11:57
Defines for better OpenCL support in CLion
#ifndef clion_defines_cl // pragma once
#define clion_defines_cl
#ifdef __CLION_IDE__
#define __kernel
#define __global
#define __local
#define __constant
#define __private