Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Thanh Nguyen magiskboy

🎯
Focusing
View GitHub Profile
View main.py
import threading
import multiprocessing
import time
import requests
def measure(func):
def f(*args, **kwargs):
start = time.time()
ret = func(*args, **kwargs)
print(f"{func.__name__} takes {time.time()-start} seconds")
View kmean-visualization.html
<html>
<head>
<title>Kmean</title>
</head>
<body>
<canvas id="kmean" width="640" height="480"></canvas>
<script type="application/javascript">
const canvas = document.getElementById("kmean");
const ctx = canvas.getContext("2d");
View async_cache.js
const lib = require("./lib");
/**
* @param {number} id
* @param {(number) => Promise<import('./lib').CacheValue>} fetcher
* @typedef {Object} Product
* @property {number} id
* @returns {Promise<Product>|undefined}
*/
async function getProductWithCached(id, fetcher) {
View ts-transform-example.ts
import ts, { SyntaxKind } from "typescript";
const source = `
function fib(n: number): number {
if (n < 2) return n;
return fib(n - 2) + fib(n - 1);
}
console.log("foo");
View build_tree_from_flat.py
class Node:
def __init__(self, key, data):
self.key = key
self.data = data
self.children = []
def display(self, level=0):
tab = " " * (level * 3)
print(tab + self.data)
for child in self.children:
@magiskboy
magiskboy / shortest_path.cpp
Created May 2, 2021 01:15
Dunamic programming
View shortest_path.cpp
#include <bits/stdc++.h>
using namespace std;
/*
* Cho đồ thị vô hướng G có N đỉnh (N≤1000) và các cạnh có trọng số dương.
* Tìm đường đi ngắn nhất từ đỉnh 1 đến đỉnh N hoặc thông báo không tồn tại đường đi.
* Simple input
* 5
* 0 1 1 5 5
View gen-bin-string.cpp
#include <bits/stdc++.h>
using namespace std;
int v[100];
int n;
void gen(int i) {
if (i == n) {
for (int j = 0; j < n; ++j) cout << v[j] << " ";
@magiskboy
magiskboy / bst.py
Last active April 11, 2021 23:45
Datastructure
View bst.py
class BST:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
@classmethod
def from_arr(cls, arr):
root = BST(arr.pop(0))
for x in arr:
View bai3.md

Ý tưởng

Do yêu cầu dữ liệu đầu vào vượt quá khả năng lưu trữ của bộ nhớ trong, ta sẽ sử dụng bộ nhớ ngoài để lưu trữ thông tin trong quá trình sắp xếp

Ta sẽ sử dụng các file được lưu trên đĩa như những mảng trong bộ nhớ trong.

Các file có đặc điểm khá giống Linked List

  • thuận tiện cho việc truy cập tuần tự
  • bất tiện cho truy cập ngẫu nhiên
@magiskboy
magiskboy / bai1.py
Created April 3, 2021 06:23
AIMESOFT test
View bai1.py
class Node:
def __init__(self, value, next):
self.value = value
self.next = next
def solve(arr):
curr = arr
while curr:
print(curr.value, end=' -> ')