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
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 / 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
@amolpujari
amolpujari / array_iteration_thoughts.md
Last active January 19, 2017 09:17 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@amolpujari
amolpujari / flatten_my_array.rb
Created September 10, 2016 05:41
flatten_my_array.rb
# This is a custom method to flatten any given array
# this is simple one to read and understand
# by name it means to accept only array, so it is known that passing any other object than array will fail
def flatten_my_array arr
new_arr = []
arr.each do |element|
if element.is_a? Array
new_arr = new_arr.concat flatten_my_array(element)
# know that Array#concat is faster way to concat two arrays in ruby
@amolpujari
amolpujari / annualized_return.rb
Created April 13, 2016 09:08
annualized_return
if investment and investment.deal and investment.deal.annual_return.present?
return investment.deal.annual_return.to_i
end
return 0 if projected_earnings.blank?
return 0 if percent_profit.blank?
return 0 if percent_profit.to_f < 1
year_diff = projected_earnings.last.distribution_date.d_date.year.to_i - DateTime.now.year.to_i
@amolpujari
amolpujari / simple_captcha.rb
Created June 9, 2015 05:21
show_simple_captcha in a liquid template
module Liquid
module Tags
module SimpleCaptcha
class HumanTest < ::Liquid::Tag
include ::ActionView::Helpers::FormTagHelper
include ::SimpleCaptcha::ViewHelper
attr_accessor :request, :session
def render(context)
@amolpujari
amolpujari / pipable.rb
Last active August 29, 2015 14:06 — forked from pcreux/pipable.rb
# Elixir has pipes `|>`. Let's try to implement those in Ruby.
#
# I want to write this:
#
# email.body | RemoveSignature | HighlightMentions | :html_safe
#
# instead of:
#
# HighlightMentions.call(RemoveSignature.call(email.body)).html_safe
#