Skip to content

Instantly share code, notes, and snippets.

View AntiKnot's full-sized avatar
🎯
Focusing

Yan.xxx AntiKnot

🎯
Focusing
View GitHub Profile
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 05:31
类计数
class Foo:
count = 0
def __init__(self, a: int):
self.a = a
self.add1()
@classmethod
def add1(cls):
cls.count += 1
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 05:34
leetcode的题目
import functools
from typing import List
class Solution(object):
def largest_nums(self, nums: List[int]) -> str:
snums = [str(item) for item in nums]
snums.sort(key=functools.cmp_to_key(self.cmp), reverse=True)
_res = ""
for i in snums:
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 05:37
zhihu上回答一个问题
test_data = "1,2,3-7,9,13,15-19"
def foo(some_array_string: str) -> list:
res = []
items = some_array_string.split(',')
for item in items:
try:
number = int(item)
res.append(number)
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 05:39
根据字符串前缀聚合
"""
# build tree with python not class
ref mowangdk
https://blog.csdn.net/bell10027/article/details/51056114
users = tree()
users['harold']['username'] = 'bell'
users['handler']['username'] = 'master'
print(json.dumps(users))
{'harold': {'username': 'bell'}, 'handler': {'username': 'master'}}
@AntiKnot
AntiKnot / wine_sort.py
Created April 2, 2020 05:48
鸡尾酒排序
test_case = [2, 4, 6, 8, 0]
def wine_sort(l):
if l is []:
return []
length = len(l)
left = 0
right = length
while left < right:
@AntiKnot
AntiKnot / demo.py
Created April 2, 2020 06:00
python rq demo
from flask import Flask
from rq import Queue
from rq.job import Job
# -----
from redis import Redis
from rq import Worker, Queue, Connection
conn = Redis()
# -----
@AntiKnot
AntiKnot / waston.py
Created April 2, 2020 06:05
IBM waston speach to text
from ibm_watson import SpeechToTextV1
speech_to_text = SpeechToTextV1(
iam_apikey='{apikey}'.format(apikey="APIKEY"),
url='{url}'.format(url="https://stream.watsonplatform.net/speech-to-text/api")
)
with open('audio-file.flac', 'rb')as audio_file:
print(speech_to_text.recognize(
audio_file, content_type='audio/flac', timestamps=True, model='zh-CN_NarrowbandModel', word_confidence=True
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 06:11
会员订阅 demo
import datetime
test_event = [
{"event": "try", "date": "2018 01-02 12:33:23", "amount": "3d"},
{"event": "buy", "date": "2018 04-02 12:33:23", "amount": "3m"},
{"event": "try", "date": "2018 05-02 12:33:23", "amount": "3d"},
{"event": "renew", "date": "2018 07-01 12:33:23", "amount": "1y"},
{"event": "renew", "date": "2018 10-01 12:33:23", "amount": "1m"},
{"event": "buy", "date": "2019 03-01 12:33:23", "amount": "1m"},
# {"event": "buy", "date": "2019 04-20 12:33:23", "amount": "0d"},
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 06:26
将多个excel文件合并成一个
# -*- coding: utf-8 -*-
# 将多个Excel文件合并成一个
import os
import xlrd
import xlsxwriter
# 打开一个excel文件
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 06:46
python heapq topk
import heapq
class TopK(object):
def __init__(self, k):
self.k = k
self.heap = []
def push(self, elem):
if len(self.heap) < self.k: