Skip to content

Instantly share code, notes, and snippets.


Siyuan Xu no1xsyzy

View GitHub Profile
import os
import sys
import time
from functools import cached_property
from multiprocessing import Pool
from PyQt5.QtCore import QObject, pyqtSignal, QThread
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget
from PyQt5.QtWidgets import QPushButton
from multiprocessing import Process, Queue
from queue import Empty
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QTimer
def calc(q):
q.put(sum(i**i for i in range(10000)))
import numpy as np
from numpy import matmul
from numpy.linalg import inv
class V2_697506(dict):
def __missing__(self, key):
x, y = key
if y == 0: # rule 1
self[x, y] = 0
no1xsyzy / auto-ssh-agent
Created Jun 10, 2020
Make ssh-agent idempotent
View auto-ssh-agent
# Usage: . /path/to/auto-ssh-agent
# Check if exists ssh-agent in current session
if env | grep -q '^SSH'; then
echo Agent pid $SSH_AGENT_PID;
# Cached ssh-agent info is user-specified
import requests
from collections import defaultdict
from itertools import count
from pprint import pprint
session = requests.Session()
session.proxies = {
'http': 'http://localhost:1081',
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 = []
You can’t perform that action at this time.