Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniil Manakovskiy WinnerOK

  • Innopolis University
View GitHub Profile
@WinnerOK
WinnerOK / vector_clock.py
Last active Sep 25, 2020
Vector clock implementation
View vector_clock.py
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)):
@WinnerOK
WinnerOK / square_multiply.py
Created Sep 16, 2020
Simple square-multiply exponentiation
View square_multiply.py
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 / client.py
Last active Sep 15, 2020
File uploading by sockets in Python
View client.py
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 / django_export_with_dependants.py
Created Jun 25, 2020
[django] export object with dependants
View django_export_with_dependants.py
# 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 / segment_intersection.go
Created Dec 7, 2019
Find out wheter segments AB CD intersect
View segment_intersection.go
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,
}
You can’t perform that action at this time.