View text_sanitizer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
View sanitizer_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SanitizerHelper | |
def sanitize text | |
text = text.to_s. | |
gsub("?xml",""). | |
gsub(/DOCTYPE|json|CDATA/,""). | |
gsub("<p><br></p>", "<br/>"). | |
gsub(/\<(script|iframe|xml|applet|body|code|em|form|html|head|header|footer|input|textarea|map|nav|pre|template|tab|var|video|canvas|audio|ruby|wbrxlink|xs|binding|soap|rdf|channel|rss)/,""). | |
gsub(/ +/," "). | |
gsub(/(\<br\>)+/,"<br>"). | |
gsub(/\n+/,"\n"). |
View serachable.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
View application_datatable.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
View json_response.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'time_difference' | |
module JsonResponse | |
extend ActiveSupport::Concern | |
LOGGER = Logger.new("#{Rails.root}/log/fast_jsonapi.log") | |
included do |
View json_response_example_for_so.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module JsonResponse | |
extend ActiveSupport::Concern | |
included do | |
end | |
module ClassMethods | |
def api_action action_name, &block |
View application_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View private_inspector.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.class_eval do | |
def private_inspect | |
memo = {} | |
self.instance_variables.inject(memo) do |memo, var| | |
memo[var] = self.instance_variable_get(var).to_s | |
memo | |
end | |
except = [:__, :_, :_ex_, :_pry_, :_out_, :_in_, :_dir_, :_file_] |
View application_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
View skype_interviews_api_ruby_example.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'jwt' | |
require 'json' | |
API_KEY = "key" | |
API_SECRET = "secret" | |
token = JWT.encode({ | |
jti: SecureRandom.hex, | |
iss: API_KEY, | |
iat: Time.now.to_i, |
NewerOlder