Skip to content

Instantly share code, notes, and snippets.

View ryz310's full-sized avatar
😁
Fine

Ryosuke Sato ryz310

😁
Fine
View GitHub Profile
@ryz310
ryz310 / test_merges.rb
Last active July 21, 2021 08:11 — forked from kelan/test_merges.rb
Test ruby hash merging speed (#merge vs #merge!).
#!/usr/bin/env ruby
# To test is using `defaults.merge(options)` or `defaults.merge!(options)`
# is faster, I ran the following:
Benchmark.bm(7) do |x|
x.report("#merge:") do
10000000.times do
defaults = {:a => 1, :b => 2, :c => 3, :d => 4}
options = {:a => "another value", :d => true}
@ryz310
ryz310 / faucet.rb
Created September 28, 2019 08:47
昔の蛇口と現代の蛇口をオブジェクト指向で表現してみた。勉強会用資料。
class Water
attr_reader :temperature, :amount
def initialize(temperature:, amount:)
@temperature = temperature
@amount = amount
end
def +(other)
total_amount = self.amount + other.amount
@ryz310
ryz310 / morning-meeting.js
Last active August 8, 2019 01:09
朝会の daily-standup-bot に投げるテキストを esa.io の日報から生成する JS。
const pbCopy = (text) => {
const tmp = document.createElement('div');
const pre = document.createElement('pre');
pre.style.webkitUserSelect = 'auto';
pre.style.userSelect = 'auto';
tmp.style.position = 'fixed';
tmp.style.right = '200%';
tmp.appendChild(pre).textContent = text;
document.body.appendChild(tmp);
document.getSelection().selectAllChildren(tmp);
@ryz310
ryz310 / settings.yml
Last active July 3, 2022 12:37
github-nippou settings
---
format:
subject: '# :sp: %{subject}'
line: '* :github: [%{title}](%{url}) by [:@%{user}:](https://github.com/%{user}) %{status}'
dictionary:
status:
merged: ':done:'
closed: ':done:'
@ryz310
ryz310 / database.gs
Last active December 7, 2016 05:47
Google スプレッドシートのスクリプトから DB に接続して結果をスプレッドシートに展開する。
// 使用例
function example() {
renderQueryResult('シート名', query(), 'A2', 'U1');
}
// SQL は <xml><![CDATA[;]] で囲むと吉。
function query() {
return <xml><![CDATA[
select
*
inherit_from: .rubocop_todo.yml
Rails:
Enabled: true
# for Rails 3.2
Rails/ActionFilter:
Enabled: false
# for Rails 3.2
@ryz310
ryz310 / feature_spec_macro.rb
Last active August 26, 2015 13:57
feature js: true のテストを実行する際、実行毎にスクリーンショットを自動的に保存します。また、scenario 内に小さな example を記述できます。scenario 内で flow(alias: chapter) ブロックを作成し、ブロック内で expect を実行すると、一連の操作をテストすることが可能となります。
# USAGE
# - spec/rails_helper.rb
# RSpec.configure do |config|
# config.include FeatureSpecMacro, type: :feature
# end
module FeatureSpecMacro
RSpec.configure do |config|
config.before(:suite) do
unless ENV['CIRCLE_ARTIFACTS']
if Dir.exist? File.join('tmp', 'screenshot')
@ryz310
ryz310 / Default.sublime-keymap
Created March 17, 2014 04:32
Sublime Text のオレオレ設定(ショートカットキー)
[
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" },
{ "keys": ["ctrl+pagedown"], "command": "next_view_in_stack" },
{ "keys": ["ctrl+pageup"], "command": "prev_view_in_stack" },
{ "keys": ["super+shift+n"], "command": "advanced_new_file"},
{ "keys": ["shift+delete"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"} }
]
@ryz310
ryz310 / Preferences.sublime-settings
Last active August 29, 2015 13:57
Sublime Text のオレオレ設定
{
"auto_find_in_selection": true,
"ensure_newline_at_eof_on_save": true,
"font_size": 13,
"ignored_packages":
[
"Vintage"
],
"rulers":
[
@ryz310
ryz310 / create_insert_into.rb
Last active August 29, 2015 13:56
FactoryGirl 等で作成したデータを Insert文に変換する
def create_insert_into(model_class)
model_class.all.each do |record|
print "insert into #{model_class.table_name} values ("
model_class.columns.each_with_index do |col, idx|
print ", " unless idx == 0
print "#{sql record.public_send(col.name)}"
end
puts ");"
end
end