Skip to content

Instantly share code, notes, and snippets.

Aashish Kiran aashish

Block or report user

Report or block aashish

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aashish
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
else
arr << x
end
@aashish
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)
end
end
@aashish
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)
super()
@canvas = page.canvas(type: :overlay)
end
def show_text(str)
@aashish
aashish / insert_image_on_pdf.rb
Last active Dec 4, 2019
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)
@aashish
aashish / DB backup and store to S3.md
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'
@aashish
aashish / elasticsearch_neo4j.md
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/

@aashish
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="http://schemas.android.com/apk/res/android"
package="com.cards.notification">
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
@aashish
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
self
else
tail = pop
if tail.kind_of? Array
flatter + tail.flatter
View gist:0557c3027975a7bec5d4
Orders table with columns serviceid, Date, name, regionid
Region table with columns id, name
service table with columns id, fees
@aashish
aashish / url_shortener.rb
Created May 16, 2015
google url shortener
View url_shortener.rb
curl https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyBm7qeH-ey9sycnGi1sy8Barqm5f1E_ESU -H 'Content-Type: application/json' -d '{"longUrl": "http://www.google.com/"}'
{
"kind": "urlshortener#url",
You can’t perform that action at this time.