Skip to content

Instantly share code, notes, and snippets.

View gevorgyana's full-sized avatar
⛩️
Focused.

Artyom Gevorgyan gevorgyana

⛩️
Focused.
View GitHub Profile
class Descriptor:
def __get__(self, instance, *args):
return getattr(instance, self.attribute_name, 'None')
def __set__(self, instance, value):
setattr(instance, self.attribute_name, value)
def __delete__(self, instance):
delattr(instance, self.attribute_name)
def __set_name__(self, owner, name):
self.attribute_name = name + "_hidden_part"
class Desc:
def __set_name__(self, owner, name):
self.field_name = name
def __get__(self, instance, *args):
if self.field_name in instance.__dict__.keys():
return instance.__dict__[self.field_name]
else:
return "NoneDescriptor"
def __set__(self, instance, value, *args):
instance.__dict__[self.field_name] = value
class Desc:
def __set_name__(self, owner, name):
self.field_name = name
def __get__(self, instance, *args):
if self.field_name in instance.__dict__.keys():
return instance.__dict__[self.field_name]
else:
return "NoneDescriptor"
def __set__(self, instance, value, *args):
instance.__dict__[self.field_name] = value
@gevorgyana
gevorgyana / meta.py
Created December 20, 2020 15:22
metaclass
from inspect import getmembers, isroutine
class Descriptor:
def __init__(self, value):
self.value = value
def __get__(self, instance, owner):
print("get")
/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2015-2017 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
fn main() {
}
/// Find a duplicate in array in O(N), with in-place modifications.
/// Iterate over the first N items. On meeting a value {v}, try to insert it
/// to index {v}, but before that, check if {input[v] == v} - if yes, return {v} as
/// the answer.
/// Finally, if nothing was found, then by birthday paradox, the last element repeats
/// some other element in the array.
fn solve(mut input: Vec<i32>) -> i32 {
struct Node {
left: Option<Box<Node>>,
right: Option<Box<Node>>,
value: i32,
l_size: usize,
r_size: usize,
reps: usize,
}
struct Tree {