Skip to content

Instantly share code, notes, and snippets.

View satoryu's full-sized avatar
🤘
Put your 🦊 up!

Tatsuya Sato satoryu

🤘
Put your 🦊 up!
View GitHub Profile
@satoryu
satoryu / life_game.rb
Last active November 7, 2023 14:30
Improve speed by using Set
View life_game.rb
N = 30
BOARDS = (N * N).times.map { |n| [n / N, n % N] }
NEIGHBORS = BOARDS.map { |(i, j)| [ [i, j], ((-1..1).to_a.product((-1..1).to_a).map { |(x, y)| [(i + x) % N, (j + y) % N] } - [[i, j]]).to_set ] }.to_h
def print_cells(cells)
BOARDS
.each_slice(N)
.map { |row| row.map { |cell| cells.include?(cell) ? '0' : '.' }.join }
.join("\n")
@satoryu
satoryu / README.md
Last active December 31, 2021 02:24
View README.md

Prerequisites

  • curl
  • jq

Usage

This script requires NICKNAME environment variable. Before run this script, define it like export NICKNAME=satoryu on bash.

View sbc-alarms.json
{
"alarms": [
{
"hours": 16,
"minutes": 11,
"message": "残りあと1時間"
},
{
"hours": 16,
"minutes": 32,
View oss-gate-workshop-in-pycon_jp-2020-sprint.md

🐍 OSS Gate Workshop in PyCon JP 2020 Sprint

OSS Gateは、OSSを初めてみたい人を対象に最初のコントリビュートを支援するワークショップを開催しています。 今回、PyCon JP さんの場所をお借りして、Sprint内でワークショップを開催いたします

Sprintについて

多くのオープンソースソフトウェアの開発は、ウェブ上でオンラインのコミュニケーションを通じて行われています。 ほとんどの場合はオンライン上で事足りますが、時には集まって共同開発を行うことが、開発を大きく前に進めるために有効なことがあります。 >

View experiment_set_trace_func.rb
# frozen_string_literal: true
# set_trace_func lambda { |event, file, line, id, binding, klass|
# if binding.receiver.to_s == 'main'
# puts "#{file}:#{line}: #{event} #{id} #{binding.receiver} [#{binding.local_variables.map(&:to_s).join(',')}]"
# end
# }
# trace = TracePoint.new(:call, :c_call) do |tp|
# puts "#{tp.lineno}: #{tp.binding.receiver}##{tp.method_id}"
View beaujolais.rb
puts (b = 'ボジョレーヌーボー'.split(//)).permutation(b.length).uniq.map(&:join).reject { |s| s =~ /ー+{2,}/ || s =~ /\A[ーョ]/ }.select { |s| s.include? 'ジョ' }
View customized_tokenizer.rb
require 'matrix'
require 'tf-idf-similarity'
class Token
def initialize(mecab_node)
@node = mecab_node
end
def valid?
@node.feature.start_with?('名詞')
View long_hair.rb
require 'matrix'
require 'tf-idf-similarity'
class Token
def initialize(mecab_node)
@node = mecab_node
end
def valid?
@node.feature.start_with?('名詞')
View dynamical_class_define.rb
module Hoge
class ArrayBase
class << self
attr_accessor :type
end
def type
self.class.type
end
@satoryu
satoryu / ohashi.rb
Created September 8, 2019 01:20
a prototype of an inerface to convert object to hash
View ohashi.rb
def hash_from(obj, keys, options={})
keys.inject({}) do |h, key|
v = obj.send(key)
h[key] = v unless options[:ignore_nil] && v.nil?
h
end
end
klass = Struct.new(:a, :b, :c)