Skip to content

Instantly share code, notes, and snippets.

@kymmt90
kymmt90 / a.rb
Created October 4, 2017 16:12
watching OpenAPI docs
initializer 'watch_open_api_docs' do |app|
app.reloaders << app.config.file_watcher.new([], { Rails.root.join('open_api_docs').to_s => ['yml'] })
config.to_prepare do
yaml = YamlRefResolver.new.resolve!(Rails.root.join('open_api_docs', 'index.yml')).to_yaml
Tempfile.create do |f|
OpenApiParser::Specification.resolve!(f.path)
end
rescue JsonSchema::Error => e
Rails.logger.error e.full_message
end
@kymmt90
kymmt90 / parse_yaml.rb
Created October 1, 2017 05:17
Append additionalProperties: false to all schemas in the OpenAPI definitions section
require 'yaml'
doc = YAML.parse(STDIN).to_ruby
doc['definitions'].transform_values! { |schema| schema.merge('additionalProperties' => false) }
puts doc.to_yaml
@kymmt90
kymmt90 / .eslintrc
Created October 16, 2016 14:51
.eslintrc
{
"env": {
"node" : true,
"browser" : true,
"es6": true
},
"ecmaFeatures" : {
"jsx": true,
},
"plugins": [
@kymmt90
kymmt90 / git-reflog.md
Last active December 28, 2022 11:42
`git reflog` についてまとめてみる

git reflog についてまとめてみる

reflog とは

  • reflog(参照ログ)とは HEAD やブランチ先端の動きの履歴
    • 各個人のローカルリポジトリに存在
    • ブランチの切り替え、新たに加えられた変更のプル、履歴の書き換え、あるいは単なる新規コミットの実行などを記録
  • git reflog で HEAD の移動履歴を、git reflog <ブランチ名> でそのブランチ先端が指していたコミットの一覧を確認可能
    • HEAD@{5}: HEAD の五つ前の状態を示す
@kymmt90
kymmt90 / file.txt
Created October 5, 2016 07:11
curl から POST した gist
curl の気持ちになって gist を POST
@kymmt90
kymmt90 / my_permutation.rb
Last active August 12, 2016 14:04
Ruby で順列
def my_permutation(sequence, r = nil)
r = sequence.size if r.nil? || sequence.size < r
result = []
enumerate(sequence, r, [], result)
result
end
def enumerate(sequence, r, one_enumeration, result)
if one_enumeration.size == r
result << one_enumeration.dup
@kymmt90
kymmt90 / kymmt_recipe.rb
Created July 24, 2016 11:50
2016-07-24 時点の kymmt.com 用 Itamae レシピ
include_recipe 'selinux::disabled'
package 'epel-release'
package 'gcc'
package 'gcc-c++'
package 'git'
package 'libyaml-devel'
package 'nginx'
package 'openssl-devel'
package 'postgresql-contrib'
@kymmt90
kymmt90 / dokaku.rb
Created July 10, 2016 09:58
Yokohama.rb #70 どう書く
class Walker
Position = Struct.new(:x, :y)
MAP = [['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h'], ['i', 'j', 'k', 'l'], ['m', 'n', 'o', 'p']]
def initialize(tiles)
@current = Position.new(1, 0)
@previous = nil
@from = nil
@tiles = tiles.split('/').map { |l| l.split('') }
end
module HookMethod
def hook_method(hook, *methods)
methods.each do |method|
orig = "#{method}_without_logging".to_sym
if instance_methods.include?(orig)
raise NameError, "#{orig} isn't a unique name"
end
alias_method orig, method
@kymmt90
kymmt90 / get_access_token.rb
Created September 22, 2015 04:37
Get Hatena OAuth access token from Ruby
#!/usr/bin/env ruby
# coding: utf-8
# The MIT License (MIT)
# Copyright (c) 2015 Kohei Yamamoto
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights