This file contains hidden or 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 sqlalchemy as sa | |
| import clickhouse_sqlalchemy as cs | |
| from sqlalchemy.orm import relationship | |
| DB_URL = "sqlite:///foo.db" | |
| e = engine = sa.create_engine(DB_URL) | |
| s = session = cs.make_session(engine) | |
| m = metadata = sa.MetaData(bind=engine) | |
| b = Base = cs.get_declarative_base(metadata=metadata) |
This file contains hidden or 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
| """ | |
| https://en.wikipedia.org/wiki/Zeller%27s_congruence | |
| https://zh.wikipedia.org/wiki/%E8%94%A1%E5%8B%92%E5%85%AC%E5%BC%8F | |
| """ | |
| from functools import wraps | |
| from icecream import ic | |
| # h is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ..., 6 = Friday) | |
| WEEK = {0: 'Sun.', | |
| 1: 'Mon.', |
This file contains hidden or 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 typing as ty | |
| from jinja2 import Template | |
| from openpyxl import Workbook | |
| from openpyxl import load_workbook | |
| from openpyxl.worksheet.worksheet import Worksheet | |
| tmpl = """ | |
| class {{ model_name }}(db.Model): | |
| {% for field in fields -%} | |
| {{ field.field_name }}=db.Column(db.{{ field.field_type }}) |
This file contains hidden or 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
| (* build a schema map find solution | |
| When a matching target is found and returned, no subsequent calculations are performed. . | |
| *) | |
| let rec do_until f array predicate= | |
| match array with | |
| | [] -> [] | |
| | hd::tl -> let hd_solution = f hd in | |
| match predicate hd_solution with | |
| | false -> do_until f tl predicate | |
| | true -> hd_solution |
This file contains hidden or 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
| """ | |
| There is a disagreement regarding the original reference handling the | |
| lambda key. | |
| And there is no need to find a closed patrol path here. Modify the extend | |
| function | |
| Refs. | |
| original https://linuxgazette.net/110/kapil.html#denouement | |
| wiki https://en.wikipedia.org/wiki/Knight%27s_tour | |
| WolframMathWord https://mathworld.wolfram.com/KnightGraph.html |
This file contains hidden or 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 os | |
| import flask_sqlalchemy | |
| from flask import Flask | |
| from sqlalchemy import func | |
| flask_app = Flask(__name__) | |
| SQLALCHEMY_DATABASE_URI = os.environ.get( | |
| 'SQLALCHEMY_DATABASE_URI', | |
| 'mysql+mysqlconnector://username:pw@addr:port/dbname') | |
| flask_app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI |
This file contains hidden or 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 collections import namedtuple | |
| from copy import deepcopy | |
| from typing import List | |
| from functools import partial | |
| Point = namedtuple('Point', ['x', 'y']) | |
| def check(p: Point, p_array: List[Point]): | |
| return all(map(partial(is_safe, p), p_array)) |
This file contains hidden or 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 LRUCache: | |
| def __init__(self, capacity): | |
| # initialize class variables | |
| self.capacity = capacity | |
| self.cache = {} | |
| self.lru = [] | |
| self.lru_count = 0 | |
| def get(self, key): | |
| # get value from cache |
This file contains hidden or 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
| # right | |
| def init_matrix(n,m): | |
| return [[0 for _ in range(n)] for _ in range(m)] | |
| # wrong | |
| # In this way, the rest of the positions will also be modified when the value is modified. | |
| def init_matrix_wrong(n,m): | |
| return [[0] * n] * m |
This file contains hidden or 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
| package main | |
| // MergeSort performs the merge sort algorithm. | |
| // Please supplement this function to accomplish the home work. | |
| func Merge(a []int64, b []int64) []int64 { | |
| size, i, j := len(a)+len(b), 0, 0 | |
| result := make([]int64, size) | |
| for k := 0; k < size; k++ { | |
| switch true { |