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
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 /
Created Mar 26, 2020
Just tired with seemingly infinite try ... finally or with ... as.
import functools
class Defers:
def __init__(self):
self._defereds = []
def add_defer(self, defer_func):
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)
(set! amount volume)
(- (+ old-amount d) volume))
# 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 <>
(define (get-group ipaddr lines)
(define group-name null)
(let/cc return
(map (λ (line)
[(parse-group-name line)
=> (λ (parsed-group-name)
def deleteorder(x):
n = len(x)
if n%2 != 0:
if any(x.count(i) > n//2 for i in set(x)):
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]
from mitmproxy import http
def request(flow: http.HTTPFlow) -> None:
if 'magicnumber' in flow.request.query:
flow.response = flow.response = http.HTTPResponse.make(200)
def response(flow: http.HTTPFlow) -> None:
flow.response.content = flow.response.content.replace(
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:
k >>= 1
if k == 0:
View remove-palindrome.rkt
#lang racket
(define (remove-palindrome s)
(define f
(lambda (i j)
[(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.