Skip to content

Instantly share code, notes, and snippets.

View amitpatelx's full-sized avatar

Amit Patel amitpatelx

View GitHub Profile
@amitpatelx
amitpatelx / Gemfile
Created September 6, 2019 08:08
Basic gems used for rspec integration in Rails
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] # for debugging
gem 'rspec-rails', '~> 3.8', '>= 3.8.2' # drop-in alternative testing framework for Minitest
gem 'factory_bot_rails' # replaces Rails fixtures
gem 'database_cleaner' # ensures a clean state for testing
end
@amitpatelx
amitpatelx / point.rb
Last active August 30, 2019 06:46
Augment Behaviour by Chaining
class Point
def initialize(x, y)
@x = x
@y = y
end
end
class Point3D < Point
def initialize(x, y, z)
super(x, y) # calls `initialize` method superclass
@amitpatelx
amitpatelx / active_transfer.rb
Created April 29, 2019 14:37
Using CommandExecutable to send file over Firefox Send
require_relative 'command_executable'
class ActiveTransfer
include CommandExecutable
def initialize(file_path)
@file_path = file_path
end
def transfer
@amitpatelx
amitpatelx / command_executable.rb
Created April 29, 2019 14:36
Execute shell command and read command output
require 'open3'
module CommandExecutable
attr_accessor :error, :output, :command_status
SPLIT_BY_NEW_LINE_REGEX = /\r?\n/
def execute_shell_command(command)
puts "+-+-+-+-+-+ Executing >>>>>>>> $ #{command.join(' ')}"
Open3.popen3(*command) do |stdin, stdout, stderr, wait_thr|
public interface MyOnClickListener {
void onClick(View v);
boolean onLongClick(View v);
}
@amitpatelx
amitpatelx / README.md
Last active February 20, 2020 08:27
BoTree Technologies Rub on Rails Exercise

Build Simple Web Application where an user can:

  1. Self Sign up to Open(create) Account
  2. Deposit money
  3. Get the current balance
  4. With positive balance a. Withdraw money b. Transfer money to another account
  5. View statement of transactions like we receive from Bank

Other Instructions

  • Use Latest Stable Version of Ruby and Rails
@amitpatelx
amitpatelx / fix_jsonb.rb
Created October 26, 2018 12:56
Fix product_info jsonb column values
# Need to run following line in production/stagin rails console after merging https://github.com/gs2589/MarketRx/pull/238
QuarantineCode.all.each do |q|
q.update!(product_info: JSON(q.product_info))
end
@amitpatelx
amitpatelx / test.sql
Created October 26, 2018 11:22
check if an attribute doesn't have null
SELECT * FROM "quarantine_codes" where (product_info->'inventory_group_attributes'->'rxcui')::text IS NOT NULL
@amitpatelx
amitpatelx / search_issue.rb
Created October 16, 2018 09:39
Investigating STAS-39
# Search product by show_name
p = Product.filter_by(show_name: 'Sildenafil').results
# Collect uniq drug names for search products
p.each_with_object([]) { |p, o| o << p.drug.name }.uniq
# => ["sildenafil 20 MG Oral Tablet", "sildenafil 100 MG Oral Tablet"]
# Search all drug with name `sildenafil`
Drug.where("name ilike '%sildenafil%'").pluck :name, :id
# => [["sildenafil 20 MG Oral Tablet", 1024], ["sildenafil 100 MG Oral Tablet", 1723], ["sildenafil 25 MG Oral Tablet", 2062], ["sildenafil 50 MG Oral Tablet", 4139], ["sildenafil 10 MG/ML Oral Suspension", 5588]]
@amitpatelx
amitpatelx / settings.local.yml
Created August 31, 2018 10:31
Sample local settings file
data_source_dir:
dispensation:
mms: '/home/amit/Downloads/market_rx_csv/MMS/'
qs1: '/home/amit/Downloads/market_rx_csv/QS1/'
offline_sandbox_ftp: '/home/amit/Downloads/market_rx_csv/offline_data/'