Skip to content

Instantly share code, notes, and snippets.


Aashish Kiran aashish

  • India
View GitHub Profile
aashish / mars_rover_problem_with_flyweight_pattern.rb
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
def land(position)
aashish / mars_rover_problem_with_proxy_pattern.rb
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
aashish / flattener.rb
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
arr << x
aashish / date_validation.rb
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)
aashish / show_char_boxes.rb
Last active Jun 6, 2018
Process char in pdf
View show_char_boxes.rb
require 'hexapdf'
class ShowTextProcessor < HexaPDF::Content::Processor
def initialize(page)
@canvas = page.canvas(type: :overlay)
def show_text(str)
aashish / insert_image_on_pdf.rb
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 ="/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)
aashish / DB backup and store to
Last active May 9, 2018
Backup database and store to AWS S3 with fog-aws
View DB backup and store to

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.


Make sure Gemfile has

gem 'fog-aws'
aashish /
Last active Jan 31, 2018
ElasticSearch with Neo4j

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.


After starting and configuring ElasticSearch and Neo4j

Add the following data to Neo4j DB at

aashish / AndroidManifest.xml
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
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
android:targetSdkVersion="17" />
aashish / array-flatter.rb
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
tail = pop
if tail.kind_of? Array
flatter + tail.flatter