Skip to content

Instantly share code, notes, and snippets.

View WinnerOK's full-sized avatar

Daniil Manakovskiy WinnerOK

  • Innopolis University
View GitHub Profile
@WinnerOK
WinnerOK / segment_intersection.go
Created December 7, 2019 09:17
Find out wheter segments AB CD intersect
type point struct {
x int
y int
}
func pointSum(p1, p2 point) point {
return point{
x: p1.x + p2.x,
y: p1.y + p2.y,
}
@WinnerOK
WinnerOK / django_export_with_dependants.py
Created June 25, 2020 09:03
[django] export object with dependants
# https://stackoverflow.com/a/30168962/6766934
from itertools import chain
from django.core import serializers
from django.contrib.admin.utils import NestedObjects
from tasks.models import SectionTypeDescriptor
collector = NestedObjects(using="default") # database name
collector.collect(SectionTypeDescriptor.objects.all())
@WinnerOK
WinnerOK / client.py
Last active September 15, 2020 10:17
File uploading by sockets in Python
import argparse
import sys
import socket
import os
# Validate that file exists.
# It was possible to use type=argparse.FileType("wb")
# But it outputs raw exception on error
def is_valid_file(parser, arg):
@WinnerOK
WinnerOK / square_multiply.py
Created September 16, 2020 08:09
Simple square-multiply exponentiation
base, exp, mod = list(map(int, input("Enter base power mod: ").split()))
r = 1
for i in bin(exp)[2:]:
bit = int(i)
r = (r * r) % mod
if bit == 1:
r = (r * base) % mod
print(f"Answer: {r}\nr == (base ** exp) % mod: {r == (base ** exp) % mod}")
@WinnerOK
WinnerOK / vector_clock.py
Last active September 25, 2020 05:07
Vector clock implementation
from multiprocessing import Process, Pipe
from os import getpid
from datetime import datetime
from time import sleep
def local_time(counter):
return '| (VECTOR_TIME={}, LOCAL_TIME={})'.format(counter, datetime.now())
def calc_recv_timestamp(recv_time_stamp, counter):
for id in range(len(counter)):