This file contains 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
def simpleblock(&block) | |
block.call | |
end | |
class Sandbox # こういうときは BasicObject 継承がいいと思うけど説明の都合でこのまま | |
end | |
def sandbox(&block) | |
Sandbox.new.instance_eval(&block) | |
end |
This file contains 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
#!/usr/bin/env ruby | |
require "json" | |
class GcpProjectMember | |
attr_reader :users, :service_accounts | |
def initialize | |
@users = Hash.new{|h,k| h[k] = [] } | |
@service_accounts = Hash.new{|h,k| h[k] = [] } | |
end |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>jenkins-agent</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/bin/java</string> | |
<string>-Dfile.encoding=UTF-8</string> |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>jenkins-agent</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/bin/java</string> | |
<string>-Dfile.encoding=UTF-8</string> |
This file contains 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
#!/usr/bin/env ruby | |
require 'benchmark' | |
require 'json' | |
require 'securerandom' | |
require 'objspace' | |
require 'active_model' | |
require 'hashie' | |
require 'dry-struct' |
This file contains 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
#!/bin/bash | |
. ../functions/base.subr | |
install_once nginx | |
# install_once nginx_config | |
# install_once rbenv | |
# ... |
This file contains 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 Array | |
def to_proc | |
->(this) { this.send(*self) } | |
end | |
end | |
[1,2,3].map(&[:+, 1]) #=> [2,3,4] | |
def apply(sym, args=[]); ->(this) { this.send(sym, *args) }; end | |
alias _ apply |
This file contains 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 'benchmark' | |
require 'active_support/all' | |
n = ARGV[0]&.to_i || 50000 | |
m = ARGV[1]&.to_i || 20 | |
arr = Array.new(m){|i| [i, [:a, :b, :c, :d].sample] }.shuffle.to_h | |
Benchmark.bmbm do |b| | |
b.report("1:") { n.times{ arr.select{|_,v| v == :a }.max&.first }} | |
b.report("2:") { n.times{ arr.each_with_object([]){|(k,v),o| o << k if v == :a }.max }} |
This file contains 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 'benchmark' | |
require 'active_support/all' | |
n = 20000 | |
m = 100 | |
arr = Array.new(m){|i| [i, [:a, :b, :c, :d].sample] }.shuffle.to_h | |
Benchmark.bmbm do |b| | |
b.report("1:") { n.times{ arr.select{|_,v| v == :a }.max&.first }} | |
b.report("2:") { n.times{ arr.each_with_object([]){|(k,v),o| o << k if v == :a }.max }} |
NewerOlder