Skip to content

Instantly share code, notes, and snippets.

View aashish's full-sized avatar

Aashish Kiran aashish

  • India
View GitHub Profile
@aashish
aashish / show_char_boxes.rb
Last active June 6, 2018 08:50
Process char in pdf
require 'hexapdf'
class ShowTextProcessor < HexaPDF::Content::Processor
def initialize(page)
super()
@canvas = page.canvas(type: :overlay)
end
def show_text(str)
@aashish
aashish / date_validation.rb
Last active October 25, 2018 12:52
Date validation
date = ARGV[0]
class Date
def self.valid?(date)
y, m, d = date.split '-'
date.match(/^\d{4}-\d{2}-\d{2}$/) && Date.valid_date?(y.to_i, m.to_i, d.to_i)
end
end
@aashish
aashish / flattener.rb
Created May 13, 2019 15:24
Array of arrays will be flattened.
class Array
def flattener
arr = []
self.each do |x|
if x.is_a? Array
arr = arr + x.flattener
else
arr << x
end
@aashish
aashish / mars_rover_problem_with_proxy_pattern.rb
Last active August 18, 2020 15:50
Mars Rover Problem with proxy pattern
class Plateau
attr_accessor :max_x, :max_y, :direction
def initialize(x, y, direction = :n)
@max_x = x.to_i
@max_y = y.to_i
@direction = direction.downcase.to_sym
end
end
@aashish
aashish / mars_rover_problem_with_flyweight_pattern.rb
Created August 20, 2020 13:23
Mars Rover Problem with Flyweight pattern
class Plateau
attr_accessor :max_x, :max_y, :direction
def initialize(x, y, direction = :n)
@max_x = x.to_i
@max_y = y.to_i
@direction = direction.downcase.to_sym
end
def land(position)