Skip to content

Instantly share code, notes, and snippets.

View kuboon's full-sized avatar
🏠
Working from home

Ohkubo KOHEI kuboon

🏠
Working from home
View GitHub Profile
@kuboon
kuboon / loop_detect.rb
Created September 8, 2025 04:13
山手線を文字数で辿っていく
require 'set'
Yamanote = %w[とうきょう ゆうらくちょう しんばし はままつちょう たまち しながわ おおさき ごたんだ めぐろ えびす しぶや はらじゅく よよぎ しんじゅく しんおおくぼ たかだのばば めじろ いけぶくろ おおつか すがも こまごめ たばた にしにっぽり にっぽり うぐいすだに うえの おかちまち あきはばら かんだ]
Station = Struct.new(:name, :val)
class Loop
def initialize(array)
@array = array.map do |a|
if a.is_a? Station
@kuboon
kuboon / http_util.rb
Created September 5, 2025 08:28
s3 presign 用に作ったけど aws-sdk-s3 が内部で uri encode するので事前に encode してはダメだったと判明し供養
module HttpUtil
class PathSegment < String
MATCHER = Regexp.new("\\A#{URI::RFC3986_Parser::SEG_NC}+\\Z")
def self.encode_from(str, allow_slash: false)
return str if str.is_a?(PathSegment)
raise 'should not include / in element or use allow_slash option to encode' if !allow_slash && str.include?('/')
new(URI.encode_uri_component(str.unicode_normalize(:nfkc)))
end
def initialize(str)
raise "invalid char: #{str}" unless MATCHER.match?(str)
RSpec.configure do |config|
config.before(:suite) { Coverage.start(oneshot_lines: true) }
config.after :suite do
coverage_data = Coverage.result(stop: true, clear: true)
uncovered_lines(coverage_data)
end
end
def parse_git_diff(base_branch)
diff_output, _stderr, _status = Open3.capture3("git diff #{base_branch} --unified=0")
@kuboon
kuboon / heroku.rb
Created January 24, 2025 05:10
rails initializer for heroku
# frozen_string_literal: true
run "heroku create #{@app_name}"
gem "pg"
file "config/database.yml", <<~CODE
development: &psql
adapter: postgresql
database: #{@app_name}
pool: 5
@kuboon
kuboon / docker-rootful-vz.yaml
Last active April 5, 2024 02:02
lima docker-rootful-vz
# A template to run ubuntu using vmType: vz instead of qemu (Default)
# This template requires Lima v0.14.0 or later and macOS 13.
vmType: "vz"
rosetta:
# Enable Rosetta for Linux.
# Hint: try `softwareupdate --install-rosetta` if Lima gets stuck at `Installing rosetta...`
enabled: true
# Register rosetta to /proc/sys/fs/binfmt_misc
binfmt: true
@kuboon
kuboon / deserialize_bench.rb
Created January 25, 2024 09:10
deserialize_bench.rb
require 'benchmark'
require 'json'
require 'active_support/notifications'
require 'active_support/cache'
array = (1..1000).map { rand }
TIMES = 1000
Benchmark.bmbm do |x|
cache = ActiveSupport::Cache::FileStore.new("./tmp/cache")
@kuboon
kuboon / dive.fish
Last active March 21, 2024 06:41
fish dive into git repo
function dive
set repo $argv[1]
if test -z (echo $repo | cut -d '/' -f3)
set repo github.com/$repo
end
set path ~/repos/$repo
if test -d $path
cd $path
echo "Moved to existing directory $path"
@kuboon
kuboon / gist:c5b8f60044de747015fe8df446bb862e
Created May 8, 2023 06:40
xorshift32 for Excel / google sheets # replace "input" to A1 or anything
=LET(LX, LAMBDA(X, A, BITXOR(X, BITLSHIFT(BITAND(X, 2^(32-A)-1), A))), RX, LAMBDA(X, A, BITXOR(X, BITRSHIFT(X, A))), LX(RX(LX(input, 13), 17), 5))
@kuboon
kuboon / .htaccess
Created February 8, 2023 04:09
rails を cgi で無理やり動かす
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi/$1 [QSA,L]
@kuboon
kuboon / Cargo.toml
Created January 5, 2023 11:47
chacha rust sample
[package]
name = "chacha"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
"chacha20poly1305" = "0.10.1"