Skip to content

Instantly share code, notes, and snippets.

View holysugar's full-sized avatar

HORII Keima holysugar

  • Aiming, Inc
  • Tokyo
View GitHub Profile
@holysugar
holysugar / dsl-sample.rb
Last active March 5, 2021 02:39
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 October 26, 2020 02:56
GCPの特定プロジェクトのメンバーリストをメンバー単位で出力する雑スクリプト
#!/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 August 20, 2019 05:51
mac で Jenkins の agent を常駐させるときの
<?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 August 20, 2019 05:51
mac で Jenkins の agent を常駐させるときの
<?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 December 20, 2018 09:45
雑ベンチ
#!/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 April 11, 2018 09:07
コンプガチャ期待値
bq.png
@holysugar
holysugar / 1.sh
Created December 21, 2017 13:52
雰囲気で shell で書いた何か
#!/bin/bash
. ../functions/base.subr
install_once nginx
# install_once nginx_config
# install_once rbenv
# ...
@holysugar
holysugar / toy.rb
Last active October 30, 2017 07:33
to_proc
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
@holysugar
holysugar / find-max-key-in-condition.rb
Last active October 10, 2017 09:33
today's bench
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 }}
@holysugar
holysugar / hash-find-max-bench.rb
Created October 10, 2017 09:18
today's bench
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 }}