{{ message }}

Instantly share code, notes, and snippets.

# Aashish Kiran aashish

• India
Created Aug 20, 2020
Mars Rover Problem with Flyweight pattern
View mars_rover_problem_with_flyweight_pattern.rb
 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)
Last active Aug 18, 2020
Mars Rover Problem with proxy pattern
View mars_rover_problem_with_proxy_pattern.rb
 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
Created May 13, 2019
Array of arrays will be flattened.
View flattener.rb
 class Array def flattener arr = [] self.each do |x| if x.is_a? Array arr = arr + x.flattener else arr << x end
Last active Oct 25, 2018
Date validation
View date_validation.rb
 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
Last active Jun 6, 2018
Process char in pdf
View show_char_boxes.rb
 require 'hexapdf' class ShowTextProcessor < HexaPDF::Content::Processor def initialize(page) super() @canvas = page.canvas(type: :overlay) end def show_text(str)
Last active Jun 13, 2021
Insert image on a existing PDF having content with hexapdf gem
View insert_image_on_pdf.rb
 require 'hexapdf' doc = HexaPDF::Document.open("/home/xxxx/Downloads/OoPdfFormExample.pdf") page = doc.pages[0] canvas = page.canvas(type: :overlay) canvas.translate(0, 20) do canvas.fill_color(0.3, 0.7, 0.7) canvas.rectangle(50, 0, 80, 80, radius: 80)
Last active May 9, 2018
Backup database and store to AWS S3 with fog-aws
View DB backup and store to S3.md

# Backup database and store to AWS S3 with fog-aws

Today I had a task to take backup of database and upload to S3. Taking the backup to local machine was straight forward job. Uploading to S3 with `fog-aws` gem was time consuming due to lack of documentation. May be this article may help you with Uploading file to S3 with fog. Since the application is already using `fog-aws` gem, I preferred to use the same gem over `aws-sdk`.

## Prerequisites

Make sure Gemfile has

``````gem 'fog-aws'
``````
Last active Jan 31, 2018
ElasticSearch with Neo4j
View elasticsearch_neo4j.md

# ElasticSearch with Neo4j Example test

Configured ElasticSearch with Neo4j as per demo app Search results are not as expected. Search results of ElasticSearch are different with Neo4j.

## Example:

After starting and configuring ElasticSearch and Neo4j

Add the following data to Neo4j DB at http://0.0.0.0:7474/browser/

Last active Sep 16, 2017 — forked from BrandonSmith/AndroidManifest.xml
Quick example of how to schedule a notification(with click listener) in the future using AlarmManager
Last active Sep 10, 2017
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers in ruby
View array-flatter.rb
 #!/usr/bin/env ruby class Array def flatter if empty? # base case self else tail = pop if tail.kind_of? Array flatter + tail.flatter