Skip to content

Instantly share code, notes, and snippets.

View tsaito-cyber's full-sized avatar

tsaito-cyber tsaito-cyber

View GitHub Profile
@tsaito-cyber
tsaito-cyber / mac_bootstrap.sh
Created October 16, 2023 15:20
mac_bootstrap.sh
#!/bin/bash -xe
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install --cask 1password
brew install 1password-cli chezmoi
open -a '1Password'
echo "chezmoi init https://github.com/takuma-saito/dotfiles"
@tsaito-cyber
tsaito-cyber / today_report.sh
Last active September 22, 2023 00:20
today_report.sh
#!/bin/bash -eu
cat <<EOF > main.rb
require 'json'
require 'date'
items = JSON.parse(\$stdin.read)
items
.group_by {|a| a['state']}
.map {|state, val| [
state,
val.sort_by {|x| x['updatedAt']}
struct TreeNode<T> {
value: T,
left: TreeNodeRef<T>,
right: TreeNodeRef<T>
}
type TreeNodeRef<T> = Option<Box<TreeNode<T>>>;
type Node = TreeNode<i64>;
@tsaito-cyber
tsaito-cyber / assume_role.sh
Created August 20, 2021 15:51
assume_role.sh
#!/bin/bash -xe
role_arn="$1"
eval $(aws sts assume-role --role-arn "$role_arn" --role-session-name $RANDOM | jq -r '.Credentials | "export AWS_ACCESS_KEY_ID=\(.AccessKeyId)\nexport AWS_SECRET_ACCESS_KEY=\(.SecretAccessKey)\nexport AWS_SESSION_TOKEN=\(.SessionToken)\n"')
0 0 2 21 2 23 15 18
4 22 24 17 12 4 11 19
3 3 11 15 5 12 6 8
18 23 6 12 18 24 15 11
9 7 19 18 16 18 14 18
2 17 10 6 5 7 20 7
5 24 5 24 18 0 1 3
24 21 6 8 21 23 18 13
@tsaito-cyber
tsaito-cyber / 0_sudoku.rb
Last active October 21, 2020 04:14
sudoku.rb
module Puzzle
class Board
include Enumerable
def initialize(board)
@board = board
end
def rows(row)
@board[row * 9, 9].compact
end
def cols(col)
@tsaito-cyber
tsaito-cyber / appstore-sign.sh
Last active August 20, 2020 08:52
appstore-sign.sh
### [apple store, appstore]
# キーと公開鍵認証リクエストを作成
$ openssl req -newkey rsa:2048 -out server.csr -keyout server.pem -days 365 -subj '/[email protected]/CN=YOUR NAME/C=JP' -batch -nodes
# キーのインポート
$ security import kaigi.pem
$ mv ~/Downloads/ios_distribution.cer kaigi.cer
$ openssl x509 -in kaigi.cer -inform DER -out kaigi.cer.pub -outform pem
@tsaito-cyber
tsaito-cyber / traversable.rb
Created May 12, 2020 16:41
traversable.rb
require 'uri'
require 'open-uri'
require 'nokogiri'
module Traversable
Target = Struct.new(:url, :depth, keyword_init: true)
def traverse(root, max_depth = 2)
root_url = URI.parse(root)
host = root_url.host
targets = [Target.new(url: root_url, depth: 0)]
@tsaito-cyber
tsaito-cyber / url_mappable.rb
Created May 12, 2020 15:12
url_mappable.rb
require 'open-uri'
module Concern
def self.extended(base)
base.instance_variable_set(:@__deps, [])
end
def included(base)
if (deps = base.instance_variable_get(:@__deps))
deps << self
else
@tsaito-cyber
tsaito-cyber / validatable.rb
Created May 12, 2020 14:13
validatable.rb
module Validatable
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def validate(attribute, &block)
attr_accessor attribute unless defined?(attribute)
alias_method "#{attribute}_orig=", "#{attribute}="
define_method("#{attribute}=") do |val|
self.__send__("#{attribute}_orig=", val) if block.(val)