Skip to content

Instantly share code, notes, and snippets.

Avatar

Yudai Tanaka ytnk531

View GitHub Profile
@ytnk531
ytnk531 / nokogiri_ex.rb
Created Jan 2, 2021
parse image on google search
View nokogiri_ex.rb
require 'uri'
require 'open-uri'
require 'net/http'
require 'bundler/inline'
require 'securerandom'
gemfile do
source 'https://rubygems.org'
gem 'nokogiri'
end
View fiddle_ex.rb
require 'fiddle'
libc = Fiddle.dlopen('libc.so.6')
printf = Fiddle::Function.new(libc['printf'],
[Fiddle::TYPE_VOIDP],
Fiddle::TYPE_INT
)
printf.call "Hello with Fiddle::Function\n"
require 'fiddle/import'
View gilded_rose.rb
class GildedRose
NAME_SULFURAS = 'Sulfuras, Hand of Ragnaros'.freeze
NAME_BRIE = 'Aged Brie'.freeze
NAME_PASS = 'Backstage passes to a TAFKAL80ETC concert'.freeze
MAX_QUALITY = 50
def initialize(items)
@items = items
end
View fiber_schedule.rb
require 'nio'
require 'fiber'
require 'timers'
require 'io/nonblock'
class Scheduler
def initialize
@selector = NIO::Selector.new
@fibers = {}
@timers = Timers::Group.new
View nio.rb
require 'nio'
selector = NIO::Selector.new
# 1234番ポートでTCPを待ち受ける
server = TCPServer.new('localhost', 1234)
# 標準出力を取得する。常にwriteが可能な口がほしいだけ
stdout = $stdout
# セレクタに登録。
View network.rb
# frozen_string_literal: true
require 'fiber'
# Manage packet.
class Packets
def initialize
@packets = []
end
View network.rb
# frozen_string_literal: true
require 'fiber'
# Manage packet.
class Packets
def initialize
@packets = []
end
View concurrent.rb
# frozen_string_literal: true
require 'concurrent'
require 'benchmark'
def api_a_call
sleep 2
'answer_from_api_a'
end
View concurrent.rb
# frozen_string_literal: true
require 'concurrent'
require 'benchmark'
def api_a_call
sleep 2
'answer_from_api_a'
end
View excels_controller.rb
class ExcelsController < ApplicationController
def show
end
def create
file = params[:file]
# ファイルを開く
workbook = RubyXL::Parser.parse file.path
# 編集する
workbook[0].add_cell 0, 0, 'changed'
You can’t perform that action at this time.