Skip to content

Instantly share code, notes, and snippets.

View liuzheng1990's full-sized avatar

Thales Liu liuzheng1990

  • Singapore
View GitHub Profile
@liuzheng1990
liuzheng1990 / cli.py
Created May 31, 2022 14:44
cli inerface for demo of downloader package
"""
The command-line interface for the downloader
"""
import argparse
from .downloader import download
def main():
parser = argparse.ArgumentParser(
description="An over-simplified downloader to demonstrate python packaging."
@liuzheng1990
liuzheng1990 / setup.py
Last active May 31, 2022 13:56
setup.py for a standard pyhon package
import setuptools
with open("README.md", "r", encoding="utf-8") as fhand:
long_description = fhand.read()
setuptools.setup(
name="over-simplified-downloader",
version="0.0.1",
author="Liu Zheng",
author_email="zheng@example.com",
@liuzheng1990
liuzheng1990 / gist:c54a6c02db5499e44e94593271f236c3
Created May 31, 2022 13:50
content of "pyproject.toml" for setup.py
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
from typing import Iterable, TypeVar, Optional
T = TypeVar('T')
def linear_search(l: Iterable[T],
target: T,
upper_limit: Optional[int]=None) -> bool:
for idx, item in enumerate(l):
def linear_search(l, target, upper_limit=None):
"""Search ``l`` (up to the ``upper_limit`` element
if specified) for ``target``. Return a boolean indicating
whether ``target`` is found in ``l`` or not.
"""
for idx, item in enumerate(l):
if item == target:
return True
if upper_limit is not None and idx >= upper_limit:
break
from typing import Iterable
def linear_search(l: Iterable, target, upper_limit=None) -> bool:
for idx, item in enumerate(l):
if item == target:
return True
if upper_limit is not None and idx >= upper_limit:
break
return False
@liuzheng1990
liuzheng1990 / example_type_var.py
Created June 29, 2021 06:38
Example of Python type variables
from typing import Iterable, TypeVar
T = TypeVar('T')
def linear_search(l: Iterable[T],
target: T,
upper_limit=None) -> bool:
for idx, item in enumerate(l):
if item == target:
return True