Skip to content

Instantly share code, notes, and snippets.

@alpaca-tc
alpaca-tc / activemodel-inspector.rb
Created September 20, 2020 08:01
こういうのが欲しいけれど、どうやったらAM::Modelに入りうるだろうか...
module ActiveModelAttributesInspector
# @return [String]
def inspect
values = attributes.map { |key, value| "#{key}: #{value.inspect}" }.join(', ')
%(<#{self.class.name} #{values}>)
end
# @param pp [PP]
#
# @return [void]
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", '~> 6.0.0'
@alpaca-tc
alpaca-tc / test.rb
Created July 5, 2020 08:47
create_or_find_byが動かないケース
# create_table :users do |t|
# t.integer :uuid, null: false
# t.index :uuid, unique: true
# end
class User < ApplicationRecord; end
User.transaction do
User.find_by(uuid: 1) #=> nil
# ここで別transactionにて
# .pryrc
show_backtrace = Class.new(Pry::ClassCommand) do
IGNORE_PATHS = %w[
/pry
/byebug
].freeze
match 'show-backtrace'
description 'Filter the caller locations'
begin
require 'bundler/inline'
rescue LoadError
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise
end
gemfile(true) do
source 'https://rubygems.org'
neovimをnodenvと併用したときのバグを発見してしまった。
vim-jpに投げるか、放置するかどうしようかなー
```neovim/0.2.2_1/share/nvim/runtime/autoload/provider/node.vim
25c25,31
< let args = [provider#node#Prog()]
---
> let args = ['node']
>
> if !empty($NVIM_NODE_HOST_DEBUG)
@alpaca-tc
alpaca-tc / automata.rb
Last active September 11, 2018 07:47
class Automata
class Error < StandardError; end
class InvalidTransition < Error; end
attr_reader :current_state
def initialize(initial_state:, &block)
@initial_state = initial_state
@current_state = nil
@events = {}
class Database
def initialize
@mutex = Mutex.new
@value = 0
end
def read
io_blocking { @value }
end
class Database
def initialize
@value = 0
end
def read
io_blocking { @value }
end
def write(value)