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 / swap_os.md
Created September 10, 2021 09:54
swap

ノートPCとデスクトップPCのデータをOSごと入れ替える(Windows, Ubuntu)

経緯・動機

  • 新しくノートPCを購入したので、デスクトップPC内のデータをOSごと移行したい。(ノートPCとデスクトップPCが逆の立場でもOK)
  • 二つのPCには異なるOSが入っているとする。(例えばノートPCにはWindows、デスクトップPCにはUbuntuがインストールされている。ここではこれを前提とする)
  • また、ノートPC内のWindowsのライセンスがもったいないので、デスクトップPCにWindowsを移行する。
  • (動機は上記だが、要は二つのOSを入れ替える作業)
  • (同じOSであれば、バックアップとその復元という形でスムーズにデータを移行するためのソフトが大抵ある)
@conf8o
conf8o / cond.py
Created July 20, 2021 04:05
cond デコレータ
from dataclasses import dataclass
class Cond:
def __init__(self):
self.conditions = []
def add(self, predicate, func):
self.conditions.append((predicate, func))
def call(self, *args, **kwargs):
@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)