Skip to content

Instantly share code, notes, and snippets.

View otokunaga2's full-sized avatar
👋

otokunaga2 otokunaga2

👋
  • Japan
  • 日本
View GitHub Profile
@otokunaga2
otokunaga2 / zod_example.ts
Last active June 11, 2024 23:52
Zod suburi
import { z } from 'zod'
// 文字列のスキーマの作成
const stringScheme = z.string()
export const userRegistrationSchema = z.object({
username: z.string(),
email: z.string().email(),
password: z.string().min(8),
});
@otokunaga2
otokunaga2 / semantic_search_with_gzip.py
Last active July 16, 2023 13:05 — forked from kyo-takano/lexical_search_with_gzip.py
Semantic Search with gzip (gzipによるセマンティック検索)
import gzip
def gzip_search(query: str, candidate_chunks: object, top_k: int=1):
"""
文字列ベースで類似したテキストチャンクを推定するアルゴリズム.
`query`, `chunk`, および`query + " " + chunk`をそれぞれgzipで圧縮し、編集距離のようなものをベースに評価する.
Parameters:
query (str): 検索クエリとして使用する文字列.
top_k (int, optional): 返される類似チャンクの上位k個を指定する (default: 1).
@otokunaga2
otokunaga2 / test_recipe_explore.rb
Created December 18, 2022 10:46
課題サポートファイル
require 'minitest/autorun'
require './lib/receipe_explore'
MiniTest.autorun
class TestReceipeExplore < Minitest::Test
def setup
@recipe_explore = RecipeExplorer.new('./receipe.tsv')
end
def test_search_keyword
@otokunaga2
otokunaga2 / IAMCredentials.json
Created September 7, 2022 09:50 — forked from ServerlessBot/IAMCredentials.json
Minimum credential set for Serverless Framework
{
"Statement": [
{
"Action": [
"apigateway:*",
"cloudformation:CancelUpdateStack",
"cloudformation:ContinueUpdateRollback",
"cloudformation:CreateChangeSet",
"cloudformation:CreateStack",
"cloudformation:CreateUploadBucket",
@otokunaga2
otokunaga2 / update-golang.md
Created September 3, 2022 01:51 — forked from nikhita/update-golang.md
How to update the Go version

How to update the Go version

System: Debian/Ubuntu/Fedora. Might work for others as well.

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by:

@otokunaga2
otokunaga2 / str_to_enum.py
Created April 23, 2022 02:06
Python enum tips
from enum import Enum
class MyEnum(Enum):
RED = 'red'
print(MyEnum('red') == MyEnum.RED)
# => True
@otokunaga2
otokunaga2 / caller.go
Created August 4, 2021 14:48 — forked from ribice/caller.go
A robust rabbitmq client for Go
go func() {
for {
err = rmq.Stream(cancelCtx)
if errors.Is(err, rabbitmq.ErrDisconnected) {
continue
}
break
}
}()
function parseUrl(url){
if (!typeof(url) == 'string'){
throw Error(`Unexpected input type, expected string but got ${typeof(url)}`)
}
let re = /^(https:\/\/www\.amazon\.co\.jp\/).*(dp|gp\/)(.*\/)/g;
const resultArray = [...url.matchAll(re)];
let urlStr;
try{
urlStr = resultArray[0][1]+resultArray[0][2]+resultArray[0][3];
return urlStr;

Reference to quick reference

app.rb
require 'sinatra'

get '/hi' do
  "Hello World!"
@otokunaga2
otokunaga2 / conerter.java
Last active April 19, 2020 15:26
Convert InputStream to byte
//https://www.techiedelight.com/convert-inputstream-byte-array-java/
private static byte[] toByteArray(InputStream in) throws IOException{
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
//Reads up to len bytes of data from the input stream into an array of bytes.
//Check: https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html#read-byte:A-
while((len = in.read(buffer)) != -1){
//指定されたバイト配列のオフセット位置offから始まるlenバイトをこのバイト配列出力ストリームに書き込みます。
os.write(buffer, 0, len);