Skip to content

Instantly share code, notes, and snippets.

View amolpujari's full-sized avatar
💭
I may be slow to respond.

Amol Pujari amolpujari

💭
I may be slow to respond.
  • Pune
View GitHub Profile
@amolpujari
amolpujari / admin.lightbox.js.coffee
Created December 19, 2013 10:41
admin.lightbox.js.coffee
window.admin ||= {}
$.extend window.admin,
lightbox:
show: (options) ->
options = {} unless options
buttonDone = options.buttonDone or "Done"
buttonCancel = options.buttonCancel or "Cancel"
focus = options.focus or "input"
@amolpujari
amolpujari / dashboard.rb
Last active March 24, 2021 11:36
activeadmin dashboard with table rows count graph
ActiveAdmin.register_page "Dashboard" do
menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }
content :title => proc{ I18n.t("active_admin.dashboard") } do
# div :class => "blank_slate_container", :id => "dashboard_default_message" do
# span :class => "blank_slate" do
# span "Welcome to Active Admin. This is the default dashboard page."
# small "To add dashboard sections, checkout 'app/admin/dashboards.rb'"
# end
@amolpujari
amolpujari / thread_pool.rb
Last active August 7, 2020 06:38
smallest thread pool in ruby
class ThreadPool
attr_accessor :threads, :max_size, :wait_time_to_free, :name
def initialize max_size=4
@max_size = max_size
@threads = []
@wait_time_to_free = 0.1
end
def start *args, &block
@amolpujari
amolpujari / application_serializer.rb
Last active April 18, 2020 06:58
rails 5 fast_jsonapi oj serializer
class ApplicationSerializer
include FastJsonapi::ObjectSerializer
#cache_options enabled: true, cache_length: 1.hour
def to_h
data = serializable_hash
if data[:data].is_a? Hash
data[:data][:attributes]
@amolpujari
amolpujari / application_job.rb
Last active April 18, 2020 06:58
rails 5 application job
class ApplicationJob < ActiveJob::Base
include ::PrivateInspector
include ::SanitizerHelper
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
@amolpujari
amolpujari / json_response_example_for_so.rb
Last active April 18, 2020 06:58
rails 5 fast_jsonapi oj serializer api action
# frozen_string_literal: true
module JsonResponse
extend ActiveSupport::Concern
included do
end
module ClassMethods
def api_action action_name, &block
@amolpujari
amolpujari / json_response.rb
Last active April 18, 2020 06:58
rails 5 fast_jsonapi oj serializer
# frozen_string_literal: true
require 'time_difference'
module JsonResponse
extend ActiveSupport::Concern
LOGGER = Logger.new("#{Rails.root}/log/fast_jsonapi.log")
included do
@amolpujari
amolpujari / application_datatable.rb
Last active April 18, 2020 06:57
rails 5 datatable
# frozen_string_literal: true
class ApplicationDatatable
delegate :params, :link_to, :strip_tags, :local_time_ago, :local_date, :current_user, :avatar,
:avatar_link, :local_time, :admin?, to: :@view
def initialize view, options={}
@view = view
@options = options
@amolpujari
amolpujari / serachable.rb
Last active April 18, 2020 06:57
rails 5 elastic search kicksearch wrapper
# frozen_string_literal: true
module Searchable
module ApplicationRecordAddition
def search_on *method_names, &import_block
send :include, ::Searchable
scope :search_import, import_block if import_block
@amolpujari
amolpujari / text_sanitizer.rb
Last active April 18, 2020 06:56
rails 5 application record text sanitizer
# frozen_string_literal: true
module TextSanitizer
extend ActiveSupport::Concern
SKIP_COLUMNS = %w{encrypted_password confirmation_token current_sign_in_ip expires_at image image_url last_sign_in_ip refresh_token}
included do
include ::SanitizerHelper
extend ::SanitizerHelper