Skip to content

Instantly share code, notes, and snippets.

View PolarNick239's full-sized avatar

Nikolai Poliarnyi PolarNick239

View GitHub Profile
@PolarNick239
PolarNick239 / create.sql
Last active January 15, 2016 10:59
DB Demo Fitness Centers
DROP VIEW IF EXISTS AreaUsers;
DROP VIEW IF EXISTS PersonActualContracts;
DROP TABLE IF EXISTS Contracts, ContractTypes, Persons, Areas, AreaTypes, Houses;
CREATE TABLE Houses (
HouseId SERIAL PRIMARY KEY NOT NULL,
Name VARCHAR(256) NOT NULL,
Address VARCHAR(1024) NOT NULL,
Phone VARCHAR(256) NOT NULL
);
@PolarNick239
PolarNick239 / teletype.hs
Created January 27, 2016 15:12
Haskell teletype
import Control.Monad.Free
import Control.Monad
import System.Exit
import Data.Traversable (traverse)
data TeletypeF next
= Say String next
| Ask (String -> next)
| Stop
@PolarNick239
PolarNick239 / download_videos.py
Last active February 14, 2016 21:09
Computer Science Center video downloader. Example page - https://compscicenter.ru/courses/comp-networks/2012-autumn/
#
# Copyright (c) 2016, Nikolay Polyarnyi
# All rights reserved.
#
# Requirements:
#
# beautifulsoup4>=4.4.1
# requests>=2.9.1
import json
@PolarNick239
PolarNick239 / boost_accurate_rationals_demo.cpp
Created April 25, 2016 16:35
Boost accurate rationals demo
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int bigint;
typedef boost::rational<bigint> rational;
/*
Online running: https://ideone.com/zTH8pK
This is example of absolutely accurate rational arithmetics with boost.
@PolarNick239
PolarNick239 / gaussian.py
Last active July 8, 2016 14:06
2D Gaussian kernel coefficients calculating and plotting
import collections
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
def makeGaussian(size, sigma=None):
if not isinstance(size, collections.Iterable):
size = (size, size)
w, h = size
@PolarNick239
PolarNick239 / aligned_allocator.h
Created July 11, 2016 16:37
Aligned allocator useful for constructing SSE intrinsics-friendly std::vector<type128, AlignedAllocator<type128, 16> >.
#pragma once
#include <cstddef>
#include <stdexcept>
#include <emmintrin.h>
#ifndef _MSC_VER
#include <mm_malloc.h>
#endif
@PolarNick239
PolarNick239 / depth_blur.py
Created September 10, 2016 18:26
Depth of field from stereo
# Example:
# depth_blur.py im3.png im4.png -16 32
# where im3.png and im4.png:
# http://vision.middlebury.edu/stereo/eval/newEval/tsukuba/im3.png
# http://vision.middlebury.edu/stereo/eval/newEval/tsukuba/im4.png
# Usage:
# move mouse over image to change depth of focus
#
# Requires pyopencl and OpenCV builded with Python support
@PolarNick239
PolarNick239 / atomicCAS_f32.cu
Last active December 29, 2016 13:54
CUDA atomicCAS for float32
__device__ float atomicCAS_f32(float *p, float cmp, float val) {
return __int_as_float(atomicCAS((int *) p, __float_as_int(cmp), __float_as_int(val)));
}
# 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) {