Skip to content

Instantly share code, notes, and snippets.

View magiskboy's full-sized avatar

Nguyễn Khắc Thành magiskboy

View GitHub Profile
── app
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ ├── models.py
│ ├── static
│ ├── templates
│ ├── tests.py
│ ├── urls.py
DEBUG = False if .getenv('DEBUG', '0') == 0 else True
STATIC_URL = '/static/'
STATIC_ROOT = '/var/demo/static'
from django.contrib.staticfiles.urls import static
from django.conf import settings
urlpatterns += static(
prefix=getattr(settings, 'STATIC_URL'),
document_root=getattr(settings, 'STATIC_ROOT')
)
server {
listen 80;
server_name demo;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
for i in range(2):
print('Hello World')
for i in range(3):
print('Hello World')

Mô hình hoá quản lí biến thể sản phẩm

Yêu cầu

  • 1 sản phẩm có nhiều nhóm biến thể
  • Mỗi nhóm biến thể đại diện bời 1 hoặc nhiều thuộc tính của sản phẩm
  • Mỗi biến thể có thể được bán bời 1 hoặc nhiều seller
  • Quản trị viên có thể quy định một số thuộc tính không được làm dùng để tạo ra nhóm biến thể
  • Quản trị viên có thể quy định một số thuộc tính bắt buộc nhập từ phía người bán
  • Người bán có quyền tạo ra nhóm biến thể và biến thể (chỉ cần xác nhận bời quản trị viên)
class Heap:
def __init__(self, compare_fn=lambda x, y: x < y):
self._data = []
self._compare_fn = compare_fn
def _swap(self, i, j):
self._data[i], self._data[j] = self._data[j], self._data[i]
@property
def top(self):
@magiskboy
magiskboy / binary_search.py
Last active August 28, 2020 06:52
basic data structures and algorithms
def binary_search(arr, key, start, end):
if start == end:
return None
mid = (start + end) // 2
val = arr[mid]
if val == key:
return mid
if key < val:
return binary_search(arr, key, start, mid)
return binary_search(arr, key, mid+1, end)