This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def once(func): | |
fst = True | |
result = None | |
@functools.wraps(func) | |
def wrapper(*args, **kwargs): | |
nonlocal fst, result | |
if fst: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
large_arr = np.random.normal(size=(3, 10000, 10000)).astype("float64") | |
np.save("example.npy", large_arr) | |
import time | |
import random | |
from numpy.lib.format import open_memmap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
import numpy as np | |
def lanczos(x, n): | |
return 0.0 if abs(x) > n else np.sinc(x) * np.sinc(x / n) | |
class Lanczos2xUpsampler(nn.Module): | |
def __init__(self, n=3): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
x = 3 | |
y = 2 | |
background = "white" | |
gap = 10 | |
duration = 100 | |
anims = [ | |
"APNGs/a1.png", | |
"APNGs/a2.png", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=AutoSSH | |
After=network.target | |
[Service] | |
User=pi | |
Group=pi | |
Type=simple | |
ExecStart=/usr/bin/autossh vps -N -R 8000:10.10.10.10:3389 | |
KillSignal=SIGQUIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
files () { | |
find "${1:-.}" -type f -not -path "*/.git/*" -not -path "*/node_modules/*" -exec file {} \; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 通常の場合 | |
yapf -r -i --style="{based_on_style: pep8, indent_width: 4, column_limit: 160}" . | |
# タブインデントの場合 | |
yapf -r -i --style="{based_on_style: pep8, indent_width: 4, use_tabs: True, column_limit: 160}" . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def shifted(list, shift=0): | |
n = len(list) | |
for i in range(shift % n, n): | |
yield list[i] | |
for i in range(0, shift % n): | |
yield list[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fix = lambda f: (lambda g: g(g))(lambda g: f(lambda *args, **kwargs: g(g)(*args, **kwargs))) | |
fact = fix(lambda f: lambda n: 1 if n == 0 else n * f(n - 1)) | |
fib = fix(lambda f: lambda x: 1 if x == 0 else 1 if x == 1 else f(x - 1) + f(x - 2)) | |
gcd = fix(lambda f: lambda a, b: abs(a) if b == 0 else f(b, a % b)) | |
tarai = fix(lambda f: lambda x, y, z: y if x <= y else f(f(x - 1, y, z), f(y - 1, z, x), f(z - 1, x, y))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics.CodeAnalysis; | |
[Serializable] | |
public struct Unit : IEquatable<Unit>, IComparable, IComparable<Unit> | |
{ | |
public override bool Equals([NotNullWhen(true)] object? obj) | |
{ | |
return obj is Unit; | |
} |