Skip to content

Instantly share code, notes, and snippets.

View lzpel's full-sized avatar

lzpel

View GitHub Profile
@lzpel
lzpel / avoid_an_unexpected_keyword_argument.py
Created January 9, 2024 14:54
avoid an unexpected keyword argument
from inspect import signature
from typing import Callable
import datetime
def print_time(text="this is"):
print(text, datetime.datetime.now())
def print_time_with_self(self, text="this is"):
@lzpel
lzpel / blender4_keyframe_linear.py
Created January 8, 2024 18:08
Blender 4.0 insert keyframes with linear interpolation
import bpy
from mathutils import Vector
# 球を作成
bpy.ops.mesh.primitive_uv_sphere_add(location=(0, 0, 0))
# 球オブジェクトを取得
sphere = bpy.context.active_object
# 移動先の座標を定義
@lzpel
lzpel / numpy_fft_example.py
Last active September 6, 2022 11:41
numpy fft example
import numpy as np
import matplotlib.pyplot as plt
def fftTest():
x = np.linspace(0, 2 * np.pi, 100)
f = -0.1 + np.sin(x) - np.cos(2 * x) # 元関数
F = np.fft.rfft(f) # 実数離散FFT
for i, Fi in enumerate(F): # FFT結果の複素数を表示
print(i, "{:2.2f}".format(Fi))
@lzpel
lzpel / simple_liner_regression.py_with_numpy.py
Last active September 4, 2022 16:49
simple liner regression with numpy
import numpy as np
import matplotlib.pyplot as plt
def generate(a, b, c, n=1000):
print("傾き {}, 切片 {}, 誤差標準偏差 {}".format(a, b, c))
x = np.arange(n)
y = a * x + b + c * np.random.normal(size=n)
return x, y
import glob
import os
const_filename_out = "out.mp4"
const_filename_list = "mylist.txt"
def print_mylist():
with open(const_filename_list, "wt") as flist:
for f in [flist, None]:
@lzpel
lzpel / sin_max98357.ino
Last active November 21, 2021 07:09
441hz sin wave for Arduino IDE and ESP32-CAM
// 参考
// https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/esp32/include/driver/include/driver/i2s.h
#include <driver/i2s.h>
static const int sample_rate=44100;
static const i2s_port_t i2s_num = I2S_NUM_0 ; // i2s port number
static const int wave_hz = 441; // 100hzは男性の声に近い周波数
static const int sample_per_cycle=sample_rate/wave_hz;
static const int max_volume=15000;
uint16_t samples_data[sample_per_cycle];
@lzpel
lzpel / helloworld_in_extended_asm.c
Last active October 17, 2021 02:26
x64 linux only. `gcc helloworld_in_extended_asm.c ; ./a.out`
int main(void){
const char mes[] = "hello, world\n\0";
asm volatile(
"movq %0, %%rsi \n\t movq %1, %%rdx \n\t movq $1, %%rax \n\t movq $1, %%rdi \n\t syscall"
:
:"r"(mes),"r"(sizeof(mes))
:
);
}
@lzpel
lzpel / index.html
Last active August 4, 2021 04:18
Character Transition SVG
<!DOCTYPE html>
<html lang="jp">
<head>
<meta charset="UTF-8">
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="480"
height="480">
<filter id="myFilter">
<feGaussianBlur stdDeviation="5">
@lzpel
lzpel / ReconcileWithCat.go
Last active July 4, 2021 04:03
ネコと和解せよ
package main
import (
"golang.org/x/image/draw"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
"golang.org/x/image/math/fixed"
"image"
"image/color"
"image/jpeg"
@lzpel
lzpel / drawJapaneseOpentype.go
Created July 4, 2021 02:51
日本語OpenTypeを画像に描画
package main
import (
"fmt"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
"golang.org/x/image/math/fixed"
"image"
"image/color"
"image/png"