Skip to content

Instantly share code, notes, and snippets.

View yasaichi's full-sized avatar
😇

Yuichi Goto yasaichi

😇
View GitHub Profile
@yasaichi
yasaichi / strict_composed_of.rb
Last active February 24, 2020 03:07
Strict mode of `composed_of` in Ruby on Rails
ApplicationRecord.singleton_class.prepend(Module.new do
def composed_of(part_id, options = {})
super(part_id, options.except(:strict))
return if !options[:strict] || !options[:mapping]
options[:mapping].flatten.each_slice(2) do |attr_name, _|
next if attr_name.to_sym == part_id.to_sym
define_method("#{attr_name}=") do |_val|
raise "Can't change the attributes mapped to `#{part_id}` directly."
(()=>{const vals={nameSei:'山田',nameMei:'太郎',kanaSei:'やまだ',kanaMei:'たろう',telNo:'09001234567',mailAddress:'test@example.com'};for(let[key,val]of Object.entries(vals)){document.getElementsByName(`OrderCreationDelivery[${key}]`).item(0).value=val;}})();
@yasaichi
yasaichi / hellworld.s
Last active August 15, 2020 12:06
Hello World in Assembly
.intel_syntax noprefix
.global main
main:
mov rdx, 14 # message length
lea rsi, [rip + message]
mov rdi, 1 # file descriptor (stdout)
mov rax, 1 # system call number (sys_write)
syscall
@yasaichi
yasaichi / index.rb
Created March 13, 2021 05:19
Hosting Rails application to Vercel
# NOTE: Put this file into `api` directory
require_relative "../config/environment"
class Handler < Rack::Handler::WEBrick
# Override
def initialize(server, *_options)
super(server, Rails.application)
end
end
@yasaichi
yasaichi / x_means.py
Last active August 31, 2022 12:18
Implementation of X-means clustering in Python
"""
以下の論文で提案された改良x-means法の実装
クラスター数を自動決定するk-meansアルゴリズムの拡張について
http://www.rd.dnc.ac.jp/~tunenori/doc/xmeans_euc.pdf
"""
import numpy as np
from scipy import stats
from sklearn.cluster import KMeans