Skip to content

Instantly share code, notes, and snippets.

module Sample
class Scope
def output
'This is output'
end
end
def self.with_scope1(&block)
Scope.new.instance_eval(&block)
end
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "activerecord"
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "activerecord"
# ref: https://speakerdeck.com/shioyama/the-ruby-module-builder-pattern?slide=65
class Predicable < Module
def initialize(*attribute_names)
@names = attribute_names
end
def included(klass)
@names.each do |name|
define_method "#{name}?" do
@MITSUBOSHI
MITSUBOSHI / how-ativerecord-rollback-act.rb
Last active March 9, 2021 10:49
To help understanding ActiveRecord::Rollback
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "activerecord"
tap "aquasecurity/trivy"
tap "argoproj/tap"
tap "brewsci/science"
tap "chezou/jumanpp"
tap "getsentry/tools"
tap "github/gh"
tap "heroku/brew"
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/core"
@MITSUBOSHI
MITSUBOSHI / github_historian.rb
Last active June 25, 2020 05:13
For finding/comparing first-parent commits in GitHub
# simple example below:
# ruby github_historian.rb -o 'kayac/ecspresso' -b v0.13.0 -a v0.15.0
require 'forwardable'
require 'optparse'
require 'open3'
class GitHubHistorian
class << self
def collect_commits(repository:, before_tag:, after_tag:, options: {})
@MITSUBOSHI
MITSUBOSHI / asana.rb
Created April 12, 2020 06:23
To prove that I'm working hard by showing asana tasks I've done.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
# Official gem is too heavy to use.
## require 'asana'
# for debugging
## require 'pry'
require 'json'
require 'faraday'
@MITSUBOSHI
MITSUBOSHI / fizzbuzz.swi
Created January 11, 2020 09:59
雑prolog
% fizzbuzz
dividable_by_15(X) :- dividable_by_5(X), dividable_by_3(X).
dividable_by_5(X) :- 0 is X mod 5.
dividable_by_3(X) :- 0 is X mod 3.
fizzbuzz(_) :- print('fizzbuzz'), nl.
fizz(_) :- print('fizz'), nl.
buzz(_) :- print('buzz'), nl.
original(X) :- print(X), nl.
@MITSUBOSHI
MITSUBOSHI / guide_to_seat.blawn
Created October 26, 2019 13:12
とりあえずBlawnで遊んでみた
class Restaurant(name)
@name = name
@function seat_area_by(guest)
seat_area = ""
if guest.is_smoker == "true"
(
seat_area.append("outside")
)
else
(