Skip to content

Instantly share code, notes, and snippets.

View lalitlogical's full-sized avatar

Lalit Kumar Maury lalitlogical

View GitHub Profile
@lalitlogical
lalitlogical / customise_devise.rb
Created December 18, 2018 06:19
customise devise for otp or reset password token
module CustomiseDevise
extend ActiveSupport::Concern
included do
attr_accessor :project_name, :mailer_host_name, :confirmation_required, :confirmation_type
after_create :send_confirmation_instructions, if: :confirmation_required?
class_eval do
def confirmation_required?
!!confirmation_required
@lalitlogical
lalitlogical / admin_generator.rb
Created January 16, 2019 11:33
Migrate RailsAdmin's model to ActiveAdmin's model
class AdminGenerator < Rails::Generators::Base
argument :name, type: :string
source_root File.expand_path('../templates', __FILE__)
desc "Generates required files."
def copy_controller_and_spec_files
@model = name.to_s.constantize
@attributes = @model.attribute_names.reject{|c| c.match(/^_id/)}.map(&:to_sym)
template "resource.rb", "app/admin/#{name.underscore}.rb"
end
@lalitlogical
lalitlogical / formatted_duration.rb
Created February 6, 2019 10:49
how to convert 270921sec into days + hours + minutes + sec ? (ruby)
t = 270921
mm, ss = t.divmod(60) #=> [4515, 21]
hh, mm = mm.divmod(60) #=> [75, 15]
dd, hh = hh.divmod(24) #=> [3, 3]
puts "%d days, %d hours, %d minutes and %d seconds" % [dd, hh, mm, ss]
#=> 3 days, 3 hours, 15 minutes and 21 seconds
ELASTICSEARCH_URL=https://****
AWS_REGION=****
AWS_ACCESS_KEY_ID=****
AWS_SECRET_ACCESS_KEY=****
@lalitlogical
lalitlogical / list_collection.rb
Created September 23, 2019 16:59
Get MongoDB collection list
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'database name')
client.collections.map {|c| puts c.namespace.gsub('database name.','') }.count
@lalitlogical
lalitlogical / timezone_extracter
Last active November 22, 2019 07:37
extract timezone from https://timezonedb.com/time-zones website
var data = [];
$("#content table tbody tr").each(function() {
timezone = {};
$(this).find('td').each(function(index) {
if (index == 0) {
timezone['countryCode'] = $(this).html();
} else if (index == 1) {
timezone['countryName'] = $(this).html();
} else if (index == 2) {
timezone['zoneName'] = $(this).find('a').html();