Skip to content

Instantly share code, notes, and snippets.

@hanaori
hanaori / bayesian_inference.R
Last active October 24, 2023 01:01
ベイズ推定コード - note記事用( https://note.com/hanaori/n/n12ce536d8484
library(rstan)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
# AB: 打席数
# H: 打数
# alpha_pre: 事前分布(ベータ分布)の α パラメータ
# beta_pre: 事前分布(ベータ分布)の β パラメータ
dat <- list(AB = 10, H = 2, alpha_pre = 2, beta_pre = 6)
@hanaori
hanaori / Vagrantfile
Created September 9, 2016 09:47
Vagrantfile(Apache入れちゃうver)
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = 'nrel/CentOS-6.5-x86_64'
config.ssh.insert_key = false
# config.vm.box_check_update = false
config.vm.define :develop do |develop|
develop.vm.hostname = 'develop'
@hanaori
hanaori / :be_all
Last active August 25, 2016 01:11
カスタムまっちゃ
# Enumerableな対象の要素の引数指定したラムダ式の結果が全て真であることを検証します。
RSpec::Matchers.define :be_all do |p|
match do |items|
@empty = true if items.empty?
return false if @empty
items.all? { |item| p.call(item) }
end
failure_message do |items|
if @empty
@hanaori
hanaori / CertainViewController.swift
Created May 6, 2016 02:04
文字数によるボタンの非活性制御
// saveボタン
@IBOutlet weak var save: UIBarButtonItem!
// UITextFieldが編集されると呼ばれるデリゲートメソッド
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
var textLength: Int;
// (UITextField の文字数 - カット、ペースト、デリートされた文字数)+ キーボードから入力された文字数
textLength = ( textField.text!.characters.count - range.length ) + string.characters.count;
register_instance_option :link_icon do
"fa fa-sort" // FontAwsome Icons
end
@hanaori
hanaori / zndoko_kiyoshi.rb
Last active March 22, 2016 03:46
巷で流行りのズンドコきよしを実装してみた
zds = []
loop.lazy.map{ ['ズン', 'ドコ'].sample }.each do |zd|
print zd
zds << zd
break if zds.last(5) == ["ズン", "ズン", "ズン", "ズン", "ドコ"]
end
print " キ・ヨ・シ!"
@hanaori
hanaori / str_utils.rake
Created March 9, 2016 08:22
英語の語尾変化確認用のrakeタスク
namespace :str_utils do
desc "英語の語尾変化を確認します。"
task :check_inflection, ['word'] => :environment do |task, args|
word = args.word
puts "単数形.......... " << word.singularize
puts "複数形.......... " << word.pluralize
puts "キャメルケース.. " << word.camelize
puts "スネークケース.. " << word.underscore
puts "テーブル名...... " << word.tableize
@hanaori
hanaori / JavaScriptのクラス
Created February 12, 2016 08:57
JavaScriptのクラスについて
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Here your code !
var Clazz = function(name) {
// インスタンスプロパティ
this.name = name;
// instance method bad
this.say = function() {
@hanaori
hanaori / rails_admin.rb
Created January 20, 2016 08:00
config/initializers/rails_admin.rb
# ファイル読み込まれ順によるエラーの恐れをなくすため、同一ファイルの先頭にRailsAdminEnumを記述しています。
module ActiveRecord
module RailsAdminEnum
def enum(definitions)
super
definitions.each do |name, values|
define_method("#{ name }_enum") { self.class.send(name.to_s.pluralize).to_a }
define_method("#{ name }=") do |value|
if value.kind_of?(String) and value.to_i.to_s == value
super value.to_i
@hanaori
hanaori / rails_admin.rb
Created January 20, 2016 07:51
config/initializers/rails_admin.rb
require Rails.root.join('lib', 'display_order_action.rb')
RailsAdmin.config do |config|
config.actions do
dashboard # mandatory
index # mandatory
new
export
bulk_delete
show