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 / rgb_to_hsv_np.py
Last active January 14, 2023 10:48
numpy RGB to HSV
#
# Copyright (c) 2016, Nikolay Polyarnyi
# All rights reserved.
#
import numpy as np
def rgb_to_hsv(rgb):
"""
@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 / atomic_cmpxchg_f32.cl
Last active January 27, 2018 19:41
OpenCL overload of atomic_cmpxchg and atomic_add for float
// See https://streamhpc.com/blog/2016-02-09/atomic-operations-for-floats-in-opencl-improved/
static float atomic_cmpxchg_f32(volatile __global float *p, float cmp, float val) {
union {
unsigned int u32;
float f32;
} cmp_union, val_union, old_union;
cmp_union.f32 = cmp;
val_union.f32 = val;
@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)));
}