Skip to content

Instantly share code, notes, and snippets.

View tomoasleep's full-sized avatar

Tomoya Chiba tomoasleep

View GitHub Profile
@tomoasleep
tomoasleep / redis-objects.rb
Created September 7, 2023 07:58
Samples of Tapioca DSL compilers
# typed: true
# frozen_string_literal: true
module Tapioca
module Compilers
class RedisObjects < Tapioca::Dsl::Compiler
extend T::Sig
ConstantType = type_member { { fixed: T.all(T::Class[::Redis::Objects], ::Redis::Objects::ClassMethods) } }
@tomoasleep
tomoasleep / sig_divider.rb
Created August 8, 2023 03:19
SigDivider divides a single RBI file into multiple files by each class or module.
# frozen_string_literal: true
require 'fileutils'
require 'rbi'
require 'active_support/all'
# SigDivider divides a single RBI file into multiple files by each class or module.
class SigDivider < RBI::Visitor
TreeWithName = Struct.new(:name, :tree, keyword_init: true)
@tomoasleep
tomoasleep / debug_helper.rb
Last active July 3, 2023 00:18
Launch postmortem debug on test failure
require 'debug'
module DebugHelper
class << self
def debug_on_error
yield
rescue => e
enter_postmortem_session(e)
raise e
end
@tomoasleep
tomoasleep / install-vscode-ruby-test-adapter.sh
Last active March 22, 2023 02:30
https://github.com/connorshea/vscode-ruby-test-adapter/pull/118 のバージョンの拡張をインストールするためのスクリプトです。
#!/bin/bash
set -ex
TMPDIR=`mktemp -d`
cd $TMPDIR
git clone -b support-debug-gem https://github.com/tomoasleep/vscode-ruby-test-adapter
cd vscode-ruby-test-adapter
@tomoasleep
tomoasleep / generate-runner-from-yard.rb
Created February 21, 2023 12:54
YARD の `@example` tag の内容を収集して Ruby コードとして出力してくれる君 (TypeProf とセットで使うと便利かも)
require "yard"
require "stringio"
require "fileutils"
Example = Struct.new(:path, :name, :code, :file, :lineno, keyword_init: true)
def generate(*args)
::YARD.parse(*args)
code_objects = ::YARD::Registry.all.select do |code_object|
// Returns R if T is a function, otherwise returns Fallback
type IsFunction<T, R, Fallback = T> = T extends (...args: any[]) => any ? R : Fallback
// Returns R if T is an object, otherwise returns Fallback
type IsObject<T, R, Fallback = T> = IsFunction<T, Fallback, (T extends object ? R : Fallback)>
// "a.b.c" => "b.c"
type Tail<S> = S extends `${string}.${infer T}`? Tail<T> : S;
// typeof Object.values(T)
@tomoasleep
tomoasleep / README.md
Last active August 8, 2022 06:20
YAML の差分を JSON Patch (https://jsonpatch.com/) として生成してくれるスクリプト

Usage

ruby ./yaml_to_json_patch.rb OLD_YAML_FILE_PATH NEW_YAML_FILE_PATH
@tomoasleep
tomoasleep / gh-montly-contributions.rb
Created January 7, 2020 05:40
Monthly の Contribution プラスα (Comment した Issue) をまとめてくれる君
# Usage: ruby gh-monthly-contributions.rb <year> <month> <organization name>
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'graphql-client'
end
require 'graphql/client'
@tomoasleep
tomoasleep / ArchiveOldEmailsWithWillArchiveLabel.gs
Created September 3, 2019 04:25
willarchive ラベルが付いた3日前以上のメールを既読にして archive するやつ
function archiveOldEmailsWithWillArchiveLabel() {
var willArchiveThreads = GmailApp.search("label:willarchive older_than:3d in:inbox");
for (var i = 0; i < willArchiveThreads.length; i++) {
willArchiveThreads[i].markRead();
willArchiveThreads[i].moveToArchive();
}
}
@tomoasleep
tomoasleep / tasklist.rb
Last active September 2, 2019 02:19
https://github.com/gjtorikian/commonmarker 使って Markdown のチェックボックス一覧取得したり、チェックボックス toggle したりできるやつ
class TaskList
attr_reader :markdown
# @param markdown [String]
def initialize(markdown)
@markdown = markdown
end
# @return [CommonMarker::Node]
def document