Skip to content

Instantly share code, notes, and snippets.

View mvoitko's full-sized avatar
🎯
Focusing

Max Voitko mvoitko

🎯
Focusing
View GitHub Profile
@mvoitko
mvoitko / LRU_Cache.py
Last active October 30, 2019 14:03
LRU Cache implemented with Doubly Linked List with sentinels and Hash Map.
from collections import deque
from dataclasses import dataclass
class LRUCache:
@dataclass
class Node:
"""Doubly Linked List (DLL) Node class to store value to be cached"""
key: int = None
val: int = None
changed: [localhost] => (item={u'folder': u'org/jenkins-ci/ui', u'version': u'1.1', u'name': u'ace-editor'})
failed: [localhost] (item={u'version': u'2.28.1', u'name': u'allure-jenkins-plugin'}) => {"changed": true, "cmd": ["java", "-jar", "/opt/jenkins-cli.jar", "-i", "/var/lib/jenkins/.ssh/jenkins_deploy_key", "-s", "http://localhost:8080/", "-remoting", "install-plugin", "https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/allure-jenkins-plugin/2.28.1/allure-jenkins-plugin-2.28.1.hpi", "-name", "allure-jenkins-plugin"], "delta": "0:00:02.250731", "end": "2019-10-22 15:36:35.991978", "item": {"name": "allure-jenkins-plugin", "version": "2.28.1"}, "msg": "non-zero return code", "rc": 1, "start": "2019-10-22 15:36:33.741247", "stderr": "\nERROR: Unexpected exception occurred while performing install-plugin command.\njava.io.FileNotFoundException: https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/allure-jenkins-plugin/2.28.1/allure-jenkins-plugin-2.28.1.hpi\n\tat sun.net.www.protocol.http.Htt
@mvoitko
mvoitko / insertionSort.cpp
Created October 11, 2019 21:30
Fast version of insertion sort algorithm
static void insertionSort(int[] a) {
for(int i = 1; i < a.length; ++i) {
// invariant x[0:i-1] sorted
// shift i_th element to its proper place
for(int j = i; j > 0 && a[j-1] > a[j]; --j) {
swap(a, j-1, j);
}
}
}
# f(x) = x*x*x + a*x + b; a, b > 0, x - integer
# find x0, such that f(x0) = c, c > 0
# Для начала найдем левую границу, выберем произвольную отрицательную точку (например -1).
# Будем удваивать ее до тех пор, пока значение в ней будет больше заданного значения.
#
# Для того, чтобы найти правую границу, выберем произвольную положительную точку (например 1).
# Будем удваивать ее до тех пор, пока значение функции в этой точке меньше заданного.
def findLeftBoard(C):
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int n = 100 * 1000;
long res = compute(n);
long endTime = System.currentTimeMillis();
System.out.println(res);
// 2.2 GHz ~ 2.2 * 10^9 op/sec
Find the number of times f() is called as a function of the input size n.
a. for (i = n; i > 1; i /= 2)
f()
a. O(log n)
b. for (i = 0; i * i < n; i++)
f()
b. O(sqrt n)
@mvoitko
mvoitko / NestedDict.py
Created July 31, 2019 08:06
NestedDict class
"""
Module for managing nested dictionary collections.
"""
# nestdict.py by Adam Szieberth (2013)
# Python 3.3+
class NestedDict(dict):
"""
Class for managing nested dictionary structures. Normally, it works
@mvoitko
mvoitko / Dockerfile
Last active July 23, 2019 12:30
Python Project Dockerfile template
FROM python:3.7.3-stretch
COPY app /app
RUN pip install pip==19.0.3
RUN pip install poetry==1.0.0a2
RUN source $HOME/.poetry/env
RUN poetry install
RUN useradd --create-home appuser
@mvoitko
mvoitko / Dockerfile
Created July 23, 2019 12:29
The elegant method of activating virtualenv in Python container
FROM ubuntu:18.04
RUN apt-get update && apt-get install \
-y --no-install-recommends python3 python3-virtualenv
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m virtualenv --python=/usr/bin/python3 $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Install dependencies:
COPY requirements.txt .
@mvoitko
mvoitko / Dockerfile
Created July 20, 2019 11:37
Docker image based on Alpine with Tensorflow
FROM python:3.6-alpine
ARG ENV
WORKDIR /app
RUN pip install -U pip
RUN pip install awscli
RUN mkdir train && \
aws s3 cp s3://{bucket}/{model_file}.model train/{model_file}.model