Skip to content

Instantly share code, notes, and snippets.

@hiroki-uchida
hiroki-uchida / pre-commit
Last active July 27, 2017 04:09
RuboCop違反のファイルのコミットを阻止する
#!/bin/sh
# 参考記事
# Gitフックを使っておかしいRubyコードをコミットできないようにする - Qiita
# http://qiita.com/yuku_t/items/ad072418290a2b01a35a
# 使い方
# このコードを `~/.git_template/hooks/pre-commit` に保存して以下のコマンドを実行します。
# `$ git config --global init.templatedir '~/.git_template'`
😄😃😀😊☺😉😍😘😚😗😙😜😝😛😳😁😔😌😒😞😣😢😂😭😪😥😰😅😓😩😫😨😱😠😡😤😖😆😋😷😎😴😵😲😟😦😧😈👿😮😬😐😕😯😶😇😏😑👲👳👮👷💂👶👦👧👨👩👴👵👱👼👸😺😸😻😽😼🙀😿😹😾👹👺🙈🙉🙊💀👽💩🔥✨🌟💫💥💢💦💧💤💨👂👀👃👅👄👍👎👌👊✊✌👋✋👐👆👇👉👈🙌🙏☝👏💪🚶🏃💃👫👪👬👭💏💑👯🙆🙅💁🙋💆💇💅👰🙎🙍🙇🎩👑👒👟👞👡👠👢👕👔👚👗🎽👖👘👙💼👜👝👛👓🎀🌂💄💛💙💜💚❤💔💗💓💕💖💞💘💌💋💍💎👤👥💬👣💭🐶🐺🐱🐭🐹🐰🐸🐯🐨🐻🐷🐽🐮🐗🐵🐒🐴🐑🐘🐼🐧🐦🐤🐥🐣🐔🐍🐢🐛🐝🐜🐞🐌🐙🐚🐠🐟🐬🐳🐋🐄🐏🐀🐃🐅🐇🐉🐎🐐🐓🐕🐖🐁🐂🐲🐡🐊🐫🐪🐆🐈🐩🐾💐🌸🌷🍀🌹🌻🌺🍁🍃🍂🌿🌾🍄🌵🌴🌲🌳🌰🌱🌼🌐🌞🌝🌚🌑🌒🌓🌔🌕🌖🌗🌘🌜🌛🌙🌍🌎🌏🌋🌌🌠⭐☀⛅☁⚡☔❄⛄🌀🌁🌈🌊🎍💝🎎🎒🎓🎏🎆🎇🎐🎑🎃👻🎅🎄🎁🎋🎉🎊🎈🎌🔮🎥📷📹📼💿📀💽💾💻📱☎📞📟📠📡📺📻🔊🔉🔈🔇🔔🔕📢📣⏳⌛⏰⌚🔓🔒🔏🔐🔑🔎💡🔦🔆🔅🔌🔋🔍🛁🛀🚿🚽🔧🔩🔨🚪🚬💣🔫🔪💊💉💰💴💵💷💶💳💸📲📧📥📤✉📩📨📯📫📪📬📭📮📦📝📄📃📑📊📈📉📜📋📅📆📇📁📂✂📌📎✒✏📏📐📕📗📘📙📓📔📒📚📖🔖📛🔬🔭📰🎨🎬🎤🎧🎼🎵🎶🎹🎻🎺🎷🎸👾🎮🃏🎴🀄🎲🎯🏈🏀⚽⚾🎾🎱🏉🎳⛳🚵🚴🏁🏇🏆🎿🏂🏊🏄🎣☕🍵🍶🍼🍺🍻🍸🍹🍷🍴🍕🍔🍟🍗🍖🍝🍛🍤🍱🍣🍥🍙🍘🍚🍜🍲🍢🍡🍳🍞🍩🍮🍦🍨🍧🎂🍰🍪🍫🍬🍭🍯🍎🍏🍊🍋🍒🍇🍉🍓🍑🍈🍌🍐🍍🍠🍆🍅🌽🏠🏡🏫🏢🏣🏥🏦🏪🏩🏨💒⛪🏬🏤🌇🌆🏯🏰⛺🏭🗼🗾🗻🌄🌅🌃🗽🌉🎠🎡⛲🎢🚢⛵🚤🚣⚓🚀✈💺🚁🚂🚊🚉🚞🚆🚄🚅🚈🚇🚝🚋🚃🚎🚌🚍🚙🚘🚗🚕🚖🚛🚚🚨🚓🚔🚒🚑🚐🚲🚡🚟🚠🚜💈🚏🎫🚦🚥⚠🚧🔰⛽🏮🎰♨🗿🎪🎭📍🚩🇯🇵🇰🇷🇩🇪🇨🇳🇺🇸🇫🇷🇪🇸🇮🇹🇷🇺🇬🇧1⃣2⃣3⃣4⃣5⃣6⃣7⃣8⃣9⃣0⃣🔟🔢#⃣🔣⬆⬇⬅➡🔠🔡🔤↗↖↘↙↔↕🔄◀▶🔼🔽↩↪ℹ⏪⏩⏫⏬⤵⤴🆗🔀🔁🔂🆕🆙🆒🆓🆖📶🎦🈁🈯🈳🈵🈴🈲🉐🈹🈺🈶🈚🚻🚹🚺🚼🚾🚰🚮🅿♿🚭🈷🈸🈂Ⓜ🛂🛄🛅🛃🉑㊙㊗🆑🆘🆔🚫🔞📵🚯🚱🚳🚷🚸⛔✳❇❎✅✴💟🆚📳📴🅰🅱🆎🅾💠➿♻♈♉♊♋♌♍♎♏♐♑♒♓⛎🔯🏧💹💲💱©®™〽〰🔝🔚🔙🔛🔜❌⭕❗❓❕❔🔃🕛🕧🕐🕜🕑🕝🕒🕞🕓🕟🕔🕠🕕🕖🕗🕘🕙🕚🕡🕢🕣🕤🕥🕦✖➕➖➗♠♥♣♦💮💯✔☑🔘🔗➰🔱🔲🔳◼◻◾◽▪▫🔺⬜⬛⚫⚪🔴🔵🔻🔶🔷🔸🔹
class String
def unescape_mb5
gsub(/\&\#x[0-9A-F]{5};/) do |match|
str = match.gsub(/\&\#x/, '0x').delete(';')
Integer(str).chr('UTF-8')
end
end
def escape_mb5
gsub(/[^\u{0}-\u{FFFF}]/) { format('&#x%X;', $&.ord) }
@hiroki-uchida
hiroki-uchida / Gemfile
Last active July 13, 2023 07:02
並列処理にも対応したSimpleCovの設定
# File: Gemfile
# 追加
group :test do
gem 'simplecov', require: false
gem 'simplecov-csv', require: false # 任意
gem 'simplecov-json', require: false # 任意
end
@hiroki-uchida
hiroki-uchida / default.rb
Last active October 19, 2017 09:38
itamae cookbook logrotate examples.
# cookbooks/logrotate/default.rb
package 'crontabs'
package 'logrotate'
service 'crond' do
action %i[start enable]
end
file '/etc/logrotate.d/rails'
@hiroki-uchida
hiroki-uchida / default.rb
Created October 19, 2017 09:45
itame cookbook. ruby install by xbuild.
# cookbooks/ruby/default.rb
# xbuildに必要なパッケージインストール
package 'git'
package 'gcc'
package 'openssl-devel'
package 'libyaml-devel'
package 'libffi-devel'
package 'readline-devel'
package 'zlib-devel'
@hiroki-uchida
hiroki-uchida / wercker.yml
Created October 21, 2017 13:54
Wercker + Rails + PostgreSQL
box: ruby:2.4.2
services:
- id: postgres:9.6
env:
POSTGRES_PASSWORD: postgres_password
POSTGRES_USER: postgres_user
build:
@hiroki-uchida
hiroki-uchida / wercker.yml
Created October 21, 2017 13:56
Wercker + Rails + MySQL
box: ruby:2.4.2
services:
- id: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_USER: test_user
MYSQL_PASSWORD: test_password
MYSQL_DATABASE: test_database
@hiroki-uchida
hiroki-uchida / default.rb
Created October 23, 2017 00:37
itamae cookbook ssh examples.
# ./cookbooks/ssh/default.rb
template '/etc/ssh/sshd_config'
service 'sshd' do
action %i[reload enable]
end
@hiroki-uchida
hiroki-uchida / example_spec.rb
Last active December 7, 2023 07:26
RSpec で Rake Task のテストをクリーンに書く
# File: spec/tasks/send_invoices_spec.rb
require "rails_helper"
describe "rake billing:send_invoices", type: :task do
it "Rails environment を読み込んでいること" do
expect(task.prerequisites).to include "environment"
end