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 / sanitizer_helper.rb
Created April 18, 2020 06:54
Sanitizer Helper
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").
@amolpujari
amolpujari / private_inspector.rb
Created September 13, 2019 07:28
inspect ruby object in private
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_]
@amolpujari
amolpujari / skype_interviews_api_ruby_example.rb
Created October 1, 2018 11:46
skype interviews api ruby example
require 'jwt'
require 'json'
API_KEY = "key"
API_SECRET = "secret"
token = JWT.encode({
jti: SecureRandom.hex,
iss: API_KEY,
iat: Time.now.to_i,
@amolpujari
amolpujari / ox_parsing.rb
Last active September 22, 2018 17:49
example of parsing large xml files in ruby using ox, define a handler, look up for a particular root element
require "awesome_print"
module XmlParsing
require "ox"
class Reader < ::Ox::Sax
def initialize file_path, target, target_handler
@target_handler = target_handler
@target = target
@file_path = file_path
require "sinatra"
require "oauth2"
DB = {
site: "http://api.local.com:3000/",
redirect_uri: "http://oauth2client:1758/callback"
}
get "/" do
DB[:uid] = params[:uid]
amol_termsheet|fast!$ rf | grep Completed
Spring is not running
20:09:45 web.1 | Completed 200 OK in 5593ms (Views: 2031.4ms | ActiveRecord: 338.0ms)
20:09:50 web.1 | Completed 200 OK in 657ms (Views: 636.6ms | ActiveRecord: 7.4ms)
20:09:58 web.1 | Completed 200 OK in 604ms (Views: 579.4ms | ActiveRecord: 7.9ms)
20:10:08 web.1 | Completed 200 OK in 639ms (Views: 616.0ms | ActiveRecord: 9.8ms)
20:10:11 web.1 | Completed 200 OK in 657ms (Views: 635.3ms | ActiveRecord: 8.5ms)
20:10:17 web.1 | Completed 200 OK in 754ms (Views: 727.1ms | ActiveRecord: 7.7ms)
20:10:19 web.1 | Completed 200 OK in 680ms (Views: 655.1ms | ActiveRecord: 8.6ms)
20:10:20 web.1 | Completed 200 OK in 553ms (Views: 528.5ms | ActiveRecord: 8.5ms)
@amolpujari
amolpujari / active_admin.rb
Created March 26, 2013 09:47
activeadmin timestamps columns, and other customizations
module ActiveAdmin
module Views
class IndexAsTable < ActiveAdmin::Component
class IndexTableFor < ::ActiveAdmin::Views::TableFor
def timestamps_columns
column :created_at, :sortable => :created_at do |resource|
resource.created_at and resource.created_at.strftime('%b %-d %Y, %l %P')
end
column :updated_at, :sortable => :updated_at do |resource|
@amolpujari
amolpujari / rvm2rbenv.txt
Created April 14, 2018 06:18 — forked from brentertz/rvm2rbenv.txt
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
### write your solution here
module M
def method_m
puts 'from m...'
end
end
module N
def method_n
In Ruby class variables are denoted by `@@`, and instance variables are denoted by `@`
Instance variables
- are private to the class instance, cannot be accessed outside class unless shared
- they cannot be accessed outside class instance methods
- they get inherited
Class variables
- are private to the class instance, cannot be accessed outside class unless shared
- they cannot be accessed outside class instance methods