This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module DeepSort | |
class Error < StandardError; end | |
refine Hash do | |
def deep_sort | |
keys = self.keys | |
raise DeepSort::Error, "Invalid Keys(#{keys})" unless keys.all? { |k| k.is_a?(String) || k.is_a?(Symbol) || k.is_a?(Numeric) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Connections | |
class ElasticsearchRelationConnection < GraphQL::Pagination::RelationConnection | |
def nodes | |
@nodes ||= limited_nodes.records.to_a | |
end | |
# Rubocopにload_nodesメソッドが不要と言われた | |
# しかし、継承元のRelationConnectionで呼ばれているのでnodesメソッドのエイリアスにしておく | |
# また、元々private methodだったので変更しておく | |
alias_method :load_nodes, :nodes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddColumnCommentFromEnum < ActiveRecord::Migration[6.0] | |
def up | |
table_with_columns.each do |table_name, columns| | |
next unless I18n.exists?("enums.#{table_name.singularize}") | |
columns.map(&:name).each do |column_name| | |
next unless I18n.exists?("enums.#{table_name.singularize}.#{column_name}") | |
model = table_name.classify.constantize | |
enums = model.send(column_name.pluralize) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddColumnCommentFromI18n < ActiveRecord::Migration[6.0] | |
def up | |
table_with_columns.each do |table_name, columns| | |
columns.map(&:name).each do |column_name| | |
next unless I18n.exists?("activerecord.attributes.#{table_name.singularize}.#{column_name}") | |
change_column_comment( | |
table_name, | |
column_name, | |
I18n.t("activerecord.attributes.#{table_name.singularize}.#{column_name}"), | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mackerel/client' | |
namespace :mackerel do | |
namespace :service_metric do | |
namespace :database do | |
desc 'Post table count, column count, and comment count to mackerel.' | |
task post: :environment do | |
client = Mackerel::Client.new(mackerel_api_key: ENV['MACKEREL_API_KEY']) | |
service_name = ENV['MACKEREL_SERVICE_NAME'] | |
time = Time.zone.now.to_i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PATH="~/bin:$PATH" | |
export GOENV_ROOT="$HOME/.goenv" | |
export PATH="$GOENV_ROOT/bin:$PATH" | |
eval "$(goenv init -)" | |
export RBENV_ROOT="$HOME/.rbenv" | |
export PATH="$RBENV_ROOT/bin:$PATH" | |
eval "$(rbenv init -)" | |
export NODENV_ROOT="$HOME/.nodenv" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ctrl + Rで、pecoでhistoryを参照 | |
function peco-select-history() { | |
# historyを番号なし、逆順、最初から表示。 | |
# 順番を保持して重複を削除。 | |
# カーソルの左側の文字列をクエリにしてpecoを起動 | |
# \nを改行に変換 | |
BUFFER="$(history -nr 1 | awk '!a[$0]++' | peco --query "$LBUFFER" | sed 's/\\n/\n/')" | |
CURSOR=$#BUFFER # カーソルを文末に移動 | |
zle -R -c # refresh | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Turbolinks from 'turbolinks'; | |
Turbolinks.start(); | |
document.addEventListener('turbolinks:load', function(event) { | |
for (let form of document.querySelectorAll('form[method=get]:not([data-remote=true])')) { | |
form.addEventListener('submit', function (event) { | |
event.preventDefault(); | |
const entries = [...new FormData(event.target).entries()]; | |
const actionUrl = new URL(event.target.action); | |
const currentUrl = new URL(location.href); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.circleci | |
.docker | |
.idea | |
.git | |
.github | |
doc | |
.env* | |
.gitignore | |
.ruby-version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function peco_git_commit --description="Select git commit message by history" | |
if set -q $argv | |
history | peco | read line | |
else | |
history | peco --query $argv | read line | |
end | |
if test -n "$line" | |
commandline "git commit -m \"$line\"" | |
end | |
set -e line |
NewerOlder