This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
processes = int(input("number of processes : ")) | |
resources = int(input("number of resources : ")) | |
max_resources = [int(i) for i in input("maximum resources : ").split()] | |
print("\n-- allocated resources for each process --") | |
currently_allocated = [[int(i) for i in input(f"process {j + 1} : ").split()] for j in range(processes)] | |
print("\n-- maximum resources for each process --") | |
max_need = [[int(i) for i in input(f"process {j + 1} : ").split()] for j in range(processes)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prettify(data, indent=' ', indent_num=0): | |
result = '' | |
if isinstance(data, list) or isinstance(data, tuple): | |
for i in data: | |
if isinstance(i, list) or isinstance(i, tuple) or isinstance(i, dict): | |
result += "{}".format(prettify(i, indent, indent_num)) | |
else: | |
result += indent * indent_num + "{}\n".format(str(i)) | |
elif isinstance(data, dict): | |
for k, v in data.items(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
def progress(percent=0, width=30): | |
left = width * percent // 100 | |
right = width - left | |
print('\r[', '#' * left, ' ' * right, ']', | |
f' {percent:.0f}%', | |
sep='', end='', flush=True) | |
for i in range(101): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import sys | |
image = Image.open(sys.argv[1]) | |
image = image.resize((10, 10), Image.ANTIALIAS) | |
image2 = Image.new('RGB', (1000, 1000)) | |
for y in range(0, 1000, 10): | |
for x in range(0, 1000, 10): | |
image2.paste(image, (x,y)) | |
image2.save(sys.argv[2], 'PNG', quality=100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderQuerySet(models.QuerySet): | |
def annotate_sold_coupon(self): | |
sold_coupons = SoldCoupon.objects.filter(sell_code=OuterRef('sold_coupon__sell_code')) | |
return self.annotate( | |
sold_coupon__sell_code=Case( | |
When(site_id=2, then=Concat(Value('SNAPP-NEW-'), 'id')), | |
When(site_id=3, then=Concat(Value('TAP30-NEW-'), 'id')), | |
When(site_id=4, then=Concat(Value('T2BON-NEW-'), 'id')) | |
), | |
sold_coupon__exist=Exists(sold_coupons.values('is_used')), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Count | |
def get_duplicated_objects(model, field, count='id'): | |
dups = model.objects.values(field).annotate(Count(count)).order_by().filter(**{"{}__count__gt".format(count): 1}).values_list(field, flat=True) | |
return model.objects.filter(**{"{}__in".format(field): dups}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 0. extract fonts into `JetBrainsMono` folder */ | |
/* 1. check fonts `urls` with your directory structure */ | |
/* normal fonts */ | |
@font-face { | |
font-family: JetBrainsMono; | |
font-style: normal; | |
font-weight: 100; | |
src: url("../fonts/JetBrainsMono/ttf/JetBrainsMono-Thin.ttf") format("truetype"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"black": "#000000", | |
"white": "#ffffff", | |
"dark": { | |
"0": "#1d2021", | |
"1": "#282828", | |
"2": "#32302f", | |
"3": "#3c3836", | |
"4": "#504945", | |
"5": "#665c54" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rotate_matrix(matrix, times): | |
times = times % 4 | |
if times == 0: | |
# a full rotation or none | |
return matrix | |
elif times == 1: | |
# for 90 forward or 270 backward | |
return [i[::-1] for i in zip(*matrix)] | |
elif times == 2: | |
# for 180 forward or backward |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_palindrome(number): | |
test_number = 0 | |
length = math.ceil(math.log10(number + 1)) | |
for i in range(length // 2): | |
test_number = (test_number * 10) + (number % 10) | |
number //= 10 | |
return number == test_number or number // 10 == test_number | |
OlderNewer