Skip to content

Instantly share code, notes, and snippets.

Siyuan Xu no1xsyzy

Block or report user

Report or block no1xsyzy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View v2ex-657839.py
import random
from decimal import *
from fractions import *
from typing import *
PRECISION = Decimal('0.0001')
def create_randoms(size: int = 30) -> List[int]:
return [random.randrange(1, 100) for _ in range(size)]
@no1xsyzy
no1xsyzy / defers.py
Created Mar 26, 2020
Just tired with seemingly infinite try ... finally or with ... as.
View defers.py
# WTFPL
import functools
class Defers:
def __init__(self):
self._defereds = []
def add_defer(self, defer_func):
self._defereds.append(defer_func)
View v2ex_645024.py
import re
PATTERN = r"/|(/[^.][^/]*|/[^/][^./][^/]*|/\.\.[^/]+)+/?"
assert re.fullmatch(PATTERN, "/abc/") is not None
assert re.fullmatch(PATTERN, "/abc/../") is None
assert re.fullmatch(PATTERN, "/abc/./") is None
assert re.fullmatch(PATTERN, "/abc/.123/") is not None
assert re.fullmatch(PATTERN, "/abc/a.123/") is not None
assert re.fullmatch(PATTERN, "/abc/a./") is not None
View example-functional-object.rkt
#lang racket
(define (cup volume)
(define amount 0)
(define (pour-in! d)
(let ([old-amount amount])
(if (> (+ old-amount d) volume)
(begin
(set! amount volume)
(- (+ old-amount d) volume))
(begin
View main.py
# coding:utf-8
import requests
import threading
from queue import Queue, Empty
import time
c_thrd = int(input("请输入要执行的线程数:"))
# 设置队列长度
workQueue = Queue(c_thrd)
# 线程池
threads = []
View v2ex619370.rkt
#lang racket
;;; Solve <https://www.v2ex.com/t/619370>
(define (get-group ipaddr lines)
(define group-name null)
(let/cc return
(map (λ (line)
(cond
[(parse-group-name line)
=> (λ (parsed-group-name)
View deleteorder.py
def deleteorder(x):
n = len(x)
if n%2 != 0:
return
if any(x.count(i) > n//2 for i in set(x)):
return
x = sorted(x)
assert all(x[i] < x[i + n//2] for i in range(n//2))
# since x[0] <= x[1] <= x[2] <= ... <= x[n-1]
# there must be x[i] <= x[i + n//2]
View mitm_keyboard_recorder.py
from mitmproxy import http
def request(flow: http.HTTPFlow) -> None:
if 'magicnumber' in flow.request.query:
print(repr(flow.request.query['magicnumber']))
flow.response = flow.response = http.HTTPResponse.make(200)
def response(flow: http.HTTPFlow) -> None:
flow.response.content = flow.response.content.replace(
b"</body>",
View singleNumber.py
import itertools, functools, operator
from typing import *
class Solution:
def singleNumber(self, lst: List[int], k: int) -> int:
pattern = []
for i in itertools.count():
if k & 1 != 0:
pattern.append(i)
k >>= 1
if k == 0:
View remove-palindrome.rkt
#lang racket
(define (remove-palindrome s)
(define f
(cachedproc
(lambda (i j)
(cond
[(equal? i j) 1]
[(equal? (+ i 1) j) 1]
;[(and (equal? (+ i 2) j) (equal? (list-ref s i) (list-ref s (- j 1)))) 1]
[(equal? (list-ref s i) (list-ref s (- j 1))) (f (+ i 1) (- j 1))]
You can’t perform that action at this time.