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
@magiskboy
magiskboy / magic.go
Created September 1, 2020 09:00
magic square generator is in python or golang
package main
import (
"fmt"
"time"
)
func MakeMagicSquare(n int) [][]int {
ret := make([][]int, n)
for i := range ret {
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)
import socket
from selectors import (
DefaultSelector,
EVENT_READ,
EVENT_WRITE,
)
import time
selector = DefaultSelector()
n_tasks = 0

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)
for i in range(2):
print('Hello World')
for i in range(3):
print('Hello World')
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;
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')
)
STATIC_URL = '/static/'
STATIC_ROOT = '/var/demo/static'