Skip to content

Instantly share code, notes, and snippets.

Avatar

Siyuan Xu no1xsyzy

View GitHub Profile
View v2_714573_2.py
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
View v2_714573.py
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)))
View main.py
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
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;
else
# Cached ssh-agent info is user-specified
_SOURCE_DIR="~/.local/run"
_SOURCE_FILE="${_SOURCE_DIR}/ssh-agent"
View fetch.py
# WTFPL
import requests
from collections import defaultdict
from itertools import count
from pprint import pprint
session = requests.Session()
session.proxies = {
'http': 'http://localhost:1081',
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 = []
You can’t perform that action at this time.