Skip to content

Instantly share code, notes, and snippets.

View aashish's full-sized avatar

Aashish Kiran aashish

  • India
View GitHub Profile
class Dictionary
attr_accessor :entries
attr_accessor :keywords
def initialize
@x = Hash.new
end
def entries
@x
@aashish
aashish / combination.rb
Last active August 29, 2015 14:01
Number of possible equations of K numbers whose sum is N
#Input: K, N (where 0 < N < ∞, 0 < K < ∞, and K <= N)
# Number of possible equations of K numbers whose sum is N
#
#Example Input: N=10 K=3
#
#Example Output:
#Total unique equations = 8
#1 + 1 + 8 = 10
#1 + 2 + 7 = 10
#1 + 3 + 6 = 10
@aashish
aashish / game_of_life.rb
Last active August 29, 2015 14:21
The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway. The "game" is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it ev…
class GameOfLife
def initialize(name, size, generations, initial_life=nil)
@size = size
@board = new_board
populate_board(initial_life)
print_board(name, 0)
reason = generations.times do |gen|
prev_board = @board
@board = evolve
@aashish
aashish / url_shortener.rb
Created May 16, 2015 13:48
google url shortener
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",
Orders table with columns serviceid, Date, name, regionid
Region table with columns id, name
service table with columns id, fees
@aashish
aashish / array-flatter.rb
Last active September 10, 2017 19:38
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers in ruby
#!/usr/bin/env ruby
class Array
def flatter
if empty? # base case
self
else
tail = pop
if tail.kind_of? Array
flatter + tail.flatter
@aashish
aashish / AndroidManifest.xml
Last active September 16, 2017 12:15 — forked from BrandonSmith/AndroidManifest.xml
Quick example of how to schedule a notification(with click listener) in the future using AlarmManager
<?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 / elasticsearch_neo4j.md
Last active January 31, 2018 15:47
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.

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 / DB backup and store to S3.md
Last active May 9, 2018 19:13
Backup database and store to AWS S3 with fog-aws

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 / insert_image_on_pdf.rb
Last active June 5, 2024 19:58
Insert image on a existing PDF having content with hexapdf gem
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)