Skip to content

Instantly share code, notes, and snippets.

@conf8o
conf8o / lisp.py
Last active April 1, 2023 05:46
lisp by python
import operator as op
from itertools import chain
def car(l):
l = iter(l)
try:
return next(l)
except StopIteration:
return None
@conf8o
conf8o / lisp.py
Last active December 18, 2022 10:11
lisp by python
import operator as op
from itertools import chain
def car(l):
l = iter(l)
try:
return next(l)
except StopIteration:
return None
@conf8o
conf8o / apilimit.py
Last active August 8, 2022 11:17
decorator to limit API requests when using Python as API client
from datetime import datetime, timedelta
class ApiLimit:
def __init__(self, request_limit, time_limit_second):
self.api_count = 0
self.request_limit = request_limit
self.time_limit_second = time_limit_second
self.start = None
def __call__(self, func):
@conf8o
conf8o / yokoidou.py
Last active September 13, 2021 09:33
横移動入力
import pyautogui as auto
import time
import random
def hold(key: str, duration: float, natural: bool=True, sd: float=0.05):
duration += random.gauss(0, sd) if natural else 0
t = time.time()
while time.time() - t < duration:
auto.keyDown(key)
@conf8o
conf8o / ast.fsx
Last active July 1, 2022 11:22
AST
type Val =
| Int of int
| Bool of bool
type Ope = Add | Mul | Lt
type Ast =
| Val of Val
| Form of Ope * Ast * Ast
let exec ope v1 v2 =
match ope, v1, v2 with
@conf8o
conf8o / SwiftAST.swift
Last active June 23, 2021 02:21
SwiftでつくるAST
enum Val {
case int(Int)
case bool(Bool)
case symbol(String)
}
enum Ope {
case add
case mul
case lt
@conf8o
conf8o / HashedPotatoField.swift
Created June 17, 2021 06:45
ハッシュテーブルの実装
protocol Potato {
func hash() -> Int
}
extension Potato where Self: Hashable {
func hash() -> Int {
return self.hashValue
}
}
@conf8o
conf8o / solve.scm
Last active June 1, 2021 09:19
競プロ用入力マクロ
; input
(define (my-read)
(let ([a (read)])
(if (symbol? a)
(symbol->string a)
a)))
(define (my-read-line)
(let ([line (read-line)])
(if (string=? "" line)
(my-read-line)
@conf8o
conf8o / 0.curriedope.py
Last active May 24, 2021 07:18
カリー化演算子(lambdaの仕様理解の旅)
import operator as ope
from functools import partial
lt, le, eq, ne, ge, gt = [(lambda x: partial(o, x)) for o in [ope.lt, ope.le, ope.eq, ope.ne, ope.ge, ope.gt]]
test = [f for f in [lt(1), le(1), eq(1), ne(1), ge(1), gt(1)]]
print(*test, sep="\n")
@conf8o
conf8o / inputloop.py
Created May 7, 2021 06:10
ユーザ入力ループ
def input_loop(question, quit):
while not quit(ans := input(question)):
yield ans
for ans in input_loop("Yo? >>", lambda x: x == "quit"):
print("Your input: ", ans)