Skip to content

Instantly share code, notes, and snippets.

View Bijendra's full-sized avatar

Bijendra singh Bijendra

View GitHub Profile
List all installed versions of java.
/usr/libexec/java_home -V
Matching Java Virtual Machines (10):
20.0.2 (x86_64) "Oracle Corporation" - "Java SE 20.0.2" /Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home
20.0.1 (x86_64) "Oracle Corporation" - "OpenJDK 20.0.1" /Library/Java/JavaVirtualMachines/jdk-20.0.1.jdk/Contents/Home
19.0.1 (x86_64) "Oracle Corporation" - "OpenJDK 19.0.1" /Library/Java/JavaVirtualMachines/jdk-19.0.1.jdk/Contents/Home
17.0.9 (x86_64) "Oracle Corporation" - "Java SE 17.0.9" /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
11.0.19 (x86_64) "Oracle Corporation" - "Java SE 11.0.19" /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
11.0.14 (x86_64) "Oracle Corporation" - "Java SE 11.0.14" /Library/Java/JavaVirtualMachines/jdk-11.0.14.jdk/Contents/Home
1.8.381.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
@Bijendra
Bijendra / rspec_results
Last active March 22, 2021 15:21
Generating Rspec reports in Rails
Rails 5.1+
Ruby 2.7
In .rspec file in project folder(app1), addd the below lines
--colour
--format html
--out rspec_results.html
@Bijendra
Bijendra / collation Rails import issue
Created March 5, 2021 06:55
Illegal mix of collations issue in database update operations in Rails
ERROR 1267 (HY000): Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '<>'
Database: MySQl
Rails application with ruby 2.5.7 and Rails 5.1.
Use case: While importing database from multiple .sql files into test db via rake tasks the collation_database parameter is giving issues.
The .sql files contains seed data which is inserted successfully.
While running rspec cases to update a given table, the error related to mix of collations is thrown in rspec logs.
To resolve this issue, changes were done in database.yml file. below line was added to force the db import with specific encoding.
@Bijendra
Bijendra / Gemfile
Last active July 28, 2019 18:10
Web crawler to fetch job detail data and build a json to consume. This crawls through multiple pages available to fetch all job listing.
require 'nokogiri'
require 'httparty'
require 'byebug'
@Bijendra
Bijendra / define_method_meta.rb
Created December 4, 2018 16:14
Ruby Metaprogramming examples
class String
def self.add_methods(name)
send(:define_method, name) {
puts "you have create a new method and output will be displayed"
}
end
end
String.add_methods("log_msg")
puts "str1".log_msg.inspect
#define_method is a private method on the class.
@Bijendra
Bijendra / employee_meta.rb
Created December 3, 2018 14:27
Ruby Meta Blogspot Example
class Employee
attr_accessor :emp_id, :emp_name, :emp_designation, :emp_department
def assign_attributes(emp_data)
emp_data.each do |k,v|
self.send("#{k}=", v)
end
end
end
@Bijendra
Bijendra / employee.rb
Last active December 3, 2018 14:19
Ruby Meta Blogspot Example
class Employee
attr_accessor :emp_id, :emp_name, :emp_designation, :emp_department
end
emp_data = { emp_id: 1, emp_name: "Employee1", emp_designation: "Level1", emp_department: "Manufacturing"}
emp_obj = Employee.new
emp_obj.emp_id = emp_data[:emp_id]
emp_obj.emp_name = emp_data[:emp_name]
emp_obj.emp_designation = emp_data[:emp_designation]
emp_obj.emp_department = emp_data[:emp_department]
@Bijendra
Bijendra / mongodb-backup-s3
Created May 8, 2014 19:50
Backup mongodb database installed on ec2 instance and store backup files over s3
#Force file syncronization and lock writes
mongo admin --eval "printjson(db.fsyncLock())"
#Above line can be commented in case of large databases as it stops write operations while making a db dump for proper sync.
MONGODUMP_PATH="/usr/bin/mongodump"
MONGO_HOST="10.0.0.51"
MONGO_PORT="27017"
MONGO_DATABASE="cv_appcloud_btoc"
MONGO_SAVE="/home/vol/expin-dump/"
TIMESTAMP=`date +%F-%H%M`
@Bijendra
Bijendra / upload-images-s3-sdk-ruby
Last active May 30, 2023 08:20
Upload images to AWS S3 in rails application using aws-sdk
Using gem aws-sdk for a ror application for uploading images to s3
Uploading images to a fixed bucket with different folders for each object or application.
The s3 keeps a limitation on the number of buckets creattion whereas there is no
limitation for content inside a bucket.
This code will upload image for a user to s3 using aws-sdk gem. The bucket and the image uploaded are made public
so that the images uploaded are directly accessible. The input it takes is the image complete path
where it is present, folder in which it should be uploaded and user_id for whom it should
be uploaded.
@Bijendra
Bijendra / Todo fixes: conover
Created September 4, 2012 07:30
Todo list for 4th: Conover
https://sourcebits.basecamphq.com/projects/8128969-success-profiler/todo_items/145021887/comments