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
function main() { | |
const output = groupNode(node2); | |
console.log(output); | |
} | |
/** | |
* Case 1: Both rows can be middle alignment | |
*/ | |
const node1 = { |
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), | |
] |
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): |
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) { |
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()) |
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") |
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"); |
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) { |
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"); |
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: |
NewerOlder