Skip to content

Instantly share code, notes, and snippets.

View belltailjp's full-sized avatar

Daichi SUZUO belltailjp

View GitHub Profile
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class A(BaseModel):
hoge: str
@belltailjp
belltailjp / csv2ical.py
Last active January 21, 2022 15:43
JリーグスケジュールCSVのical変換(MITライセンス)
import argparse
import datetime
import os
import re
import textwrap
def icalentry(cols):
day = re.sub(r'\(.+\)', '', cols[3])
ko = "{}/{} {}".format(cols[0], day, cols[4] or '00:00')
@belltailjp
belltailjp / 1_orig_optuna_example.py
Last active September 8, 2021 09:23
ppe-config based optuna
import optuna
# https://optuna.org/
def objective(trial):
x = trial.suggest_uniform('x', -10, 10)
return (x - 2) ** 2
import argparse
import glob
import os
import time
import numpy as np
from torch.utils.data import DataLoader
from pfio.cache import MultiprocessFileCache
from pfio.cache import FileCache
@belltailjp
belltailjp / toggle_zeal.sh
Last active April 8, 2019 08:13
Toggle Zeal window active
#!/bin/sh
# Launch zeal, and bring it to top screen
# If it is already on top, bring it to the back (toggle)
DEBUG=0
if [ ! -e /usr/bin/zeal ]; then
if [ $DEBUG ]; then
echo "Zeal not found in /usr/bin/zeal"
@belltailjp
belltailjp / db_insertion_benchmark_with_or_without_index.ipynb
Created January 22, 2019 04:08
Python+SQLite+Peewee Squeeze insertion performance challenge
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@belltailjp
belltailjp / cmdscale.py
Last active June 17, 2019 21:55
Multi-Dimensional Scaling (also as known as Principal Coordinate Analysis) by Python
import matplotlib.pyplot as plt
import numpy as np
from sklearn import manifold
cities = "Athens Barcelona Brussels Calais Cherbourg Cologne Copenhagen Geneva Gibraltar Hamburg HookOfHolland Lisbon Lyons Madrid Marseilles Milan Munich Paris Rome Stockholm Vienna".split(" ")
d = np.array([
# from eurodist dataset: https://rstudio-pubs-static.s3.amazonaws.com/221886_5c57ad0f5ff546e8af6386162f29fabc.html
[ 0, 3313, 2963, 3175, 3339, 2762, 3276, 2610, 4485, 2977, 3030, 4532, 2753, 3949, 2865, 2282, 2179, 3000, 817, 3927, 1991],
[3313, 0, 1318, 1326, 1294, 1498, 2218, 803, 1172, 2018, 1490, 1305, 645, 636, 521, 1014, 1365, 1033, 1460, 2868, 1802],
[2963, 1318, 0, 204, 583, 206, 966, 677, 2256, 597, 172, 2084, 690, 1558, 1011, 925, 747, 285, 1511, 1616, 1175],
@belltailjp
belltailjp / cost_vgg.py
Last active October 17, 2018 07:43
chainer_computational_cost (used from a blog post in daily.belltail.jp)
import chainer
import chainer.links as L
import numpy as np
import chainer_computational_cost as c3
net = L.VGG16Layers()
x = np.random.random((1, 3, 224, 224)).astype(np.float32) # dummy input
with chainer.no_backprop_mode(), chainer.using_config('train', False):
with c3.ComputationalCostHook(fma_1flop=True) as cch:
y = net(x)
@belltailjp
belltailjp / .zshrc
Created February 12, 2018 09:09
Force naming tmux session
if [ ! -z $TMUX ]; then
tmux show-options | grep "TMUX_NO_FORCE_NAME_SESSION" > /dev/null
if [ $? -ne 0 ]; then
SESSION_NAME=`tmux display-message -p '#S'`
echo $SESSION_NAME | grep "^[0-9]\+$" > /dev/null
if [ $? -eq 0 ]; then # Not named
/bin/echo -n "tmux session name: "
read NAME
if [ ! -z $NAME ]; then
tmux rename-session $NAME
@belltailjp
belltailjp / optional.cpp
Created December 26, 2017 12:01
Just a confirm of whether all the information of optional is preserved or not after memory bytes copy
#include <iostream>
#include <experimental/optional>
int main()
{
std::experimental::optional<int> t;
//t = 100; // comment in/out
unsigned char *p = new unsigned char[sizeof(t)];