View main_1.py
This file contains 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 queue import LifoQueue | |
import time | |
d = [ | |
(0, 1), | |
(1, 0), | |
(-1, 0), | |
(0, -1), | |
] |
View parser.py
This file contains 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
# STATE | |
STATE_METHOD = 0 | |
STATE_PATH = 1 | |
STATE_HTTP_VERSION = 2 | |
STATE_HEADER = 3 | |
STATE_BODY = 4 | |
class ParserBase: | |
def __init__(self, protocol): |
View sandbox.js
This file contains 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
const { Console } = require("console"); | |
const stream = require("stream"); | |
const sandboxProxies = new WeakMap(); | |
function compileCode(src) { | |
src = 'with (sandbox) {' + src + '}'; | |
const code = new Function('sandbox', src); | |
return function(sandbox) { |
View application.py
This file contains 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 urllib.parse import parse_qs | |
import json | |
class Headers(dict): | |
def __setitem__(self, k, v): | |
super().__setitem__(k.lower(), v) | |
def __getitem__(self, k): | |
return super().__getitem__(k.lower()) |
View python_paralell.py
This file contains 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
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
This file contains 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
<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
This file contains 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
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
This file contains 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
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
This file contains 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 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: |
View shortest_path.cpp
This file contains 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
#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 |
NewerOlder