Skip to content

Instantly share code, notes, and snippets.

View dsl-sample.rb
def simpleblock(&block)
block.call
end
class Sandbox # こういうときは BasicObject 継承がいいと思うけど説明の都合でこのまま
end
def sandbox(&block)
Sandbox.new.instance_eval(&block)
end
@holysugar
holysugar / gist:b22b31f4a48b4add5a5671267dd8ccde
Created Oct 26, 2020
GCPの特定プロジェクトのメンバーリストをメンバー単位で出力する雑スクリプト
View gist:b22b31f4a48b4add5a5671267dd8ccde
#!/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
@holysugar
holysugar / jenkins-agent.plist
Created Aug 20, 2019
mac で Jenkins の agent を常駐させるときの
View jenkins-agent.plist
<?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>
@holysugar
holysugar / jenkins-agent.plist
Created Aug 20, 2019
mac で Jenkins の agent を常駐させるときの
View jenkins-agent.plist
<?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>
@holysugar
holysugar / bench.rb
Last active Dec 20, 2018
雑ベンチ
View bench.rb
#!/usr/bin/env ruby
require 'benchmark'
require 'json'
require 'securerandom'
require 'objspace'
require 'active_model'
require 'hashie'
require 'dry-struct'
@holysugar
holysugar / bq.png
Last active Apr 11, 2018
コンプガチャ期待値
@holysugar
holysugar / 1.sh
Created Dec 21, 2017
雰囲気で shell で書いた何か
View 1.sh
#!/bin/bash
. ../functions/base.subr
install_once nginx
# install_once nginx_config
# install_once rbenv
# ...
View toy.rb
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
View find-max-key-in-condition.rb
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 }}
View hash-find-max-bench.rb
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 }}