Skip to content

Instantly share code, notes, and snippets.

View odashi's full-sized avatar
🏠
Working from home

Yusuke Oda odashi

🏠
Working from home
View GitHub Profile
@odashi
odashi / class_fastapi_app.py
Last active April 13, 2023 15:14
FastAPI server defined on a class
# Sometimes you want to define your FastAPI app within a class for some reason, e.g.,
# you wanted to initialize the servers at the point you intended, not the point of import.
#
# In this case, @app.method decorator doesn't work as-is with instance methods due to the
# difference of its signature.
#
# You need to manually call the decorator as a usual function after obtaining self (e.g.,
# in the __init__ method like below) rather than using the decorator syntax.
class MyApp:
@odashi
odashi / nai_prompt_generator.py
Last active October 26, 2022 14:57
Colab UI to generate NovelAI prompts.
!pip install ipywidgets &> /dev/null
import ipywidgets as wgt
controls = wgt.VBox([])
add_button = wgt.Button(description="Add", icon="plus")
pos_prompt_area = wgt.Textarea(placeholder="Positive prompts appear here.")
neg_prompt_area = wgt.Textarea(placeholder="Negative prompts appear here.")
ui = wgt.VBox([pos_prompt_area, neg_prompt_area, add_button, controls])
def generate_prompt(change):
@odashi
odashi / should_mute_on_twitter.txt
Last active December 26, 2022 13:02
should_mute.txt
あまり大きな声で言えないのですが
あまり知られてないのですが
ありえない
あんまり言いたくないけど
いい加減にしてほしい
いい歳してお恥ずかしいのですが
悪用厳禁なのですが
安心してください
言いたくない過去を言うと
言わせてください
@odashi
odashi / delete_old_tweets.py
Last active July 26, 2023 20:35
Cloud Functions script to delete old tweets.
import datetime
import logging
import os
from google.cloud import logging as cloud_logging
import tweepy
THRESHOLD_DAYS = 3
BATCH_SIZE = 25
@odashi
odashi / print-xml.py
Last active December 1, 2021 07:14
Pretty-prints XML file.
#!/usr/bin/env python3
import argparse
from xml.dom import minidom
def main():
p = argparse.ArgumentParser(description='Pretty-print an XML file.')
p.add_argument('file', type=str, help='File path to print.')
args = p.parse_args()
data = open(args.file).read()
@odashi
odashi / kytea_word_segmenter.cc
Last active January 26, 2021 07:11
Simple KyTea word segmenter-only pipeline.
// Wrapper class of KyTea word segmenter.
// Author: odashi
// Date: 2021-01-26
// License: MIT
#include <memory>
#include <string>
#include "kytea/kytea.h"
#include "kytea/string-util.h"
@odashi
odashi / jax_dataclass.py
Last active February 19, 2021 23:47
Augmented dataclass for JAX pytree.
import dataclasses as dc
from jax import tree_util as jt
def register_jax_dataclass(cls):
"""Registers a dataclass as a JAX pytree."""
if not dc.is_dataclass(cls):
raise TypeError('%s is not a dataclass.' % cls)
keys = [field.name for field in dc.fields(cls)]
@odashi
odashi / imake.zsh
Last active February 24, 2019 09:12
Performs a command when the content of a directory changed.
#!/bin/zsh
autoload colors; colors
if [ $# != 2 ]; then
echo "usage: $0 <root-dir> <command>"
exit 1
fi
ROOTDIR=$1
@odashi
odashi / cudnn_convolution_forward.cu
Created January 8, 2018 15:40
Example usage of cuDNN convolution forward functions.
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cuda.h>
#include <cudnn.h>
#define CUDA_CALL(f) { \
cudaError_t err = (f); \
@odashi
odashi / primitiv_xor.cc
Last active December 26, 2017 03:10
primitiv examples for Qiita (C++11/Python3)
// 実行方法:
// g++ -std=c++11 xor.cc -lprimitiv && ./a.out
#include <cstdio>
#include <iostream>
#include <primitiv/primitiv.h>
using namespace primitiv;
namespace D = primitiv::devices;
namespace F = primitiv::functions;