Skip to content

Instantly share code, notes, and snippets.

View pecha7x's full-sized avatar
🚀

Artyom Pechyorin pecha7x

🚀
View GitHub Profile
comment =
init: ->
do @deleteComment
do @newComment
newComment: ->
$('#contact #send').click (e) ->
e.preventDefault()
comment.addComment()
@pecha7x
pecha7x / response
Last active October 25, 2015 18:50
# (1) Is there something wrong with the following code:
class User < ActiveRecord::Base
scope :find_by_age, ->(age) { where("users.age = #{age}") }
end
# If yes, please tell why. If not, please tell how to order all records by id.
-----
Resp: yes, it's wrong. somebody forgot set '' for arg and AR will generate wrong select.
solutions:
scope :find_by_age, ->(age) { where("users.age = '#{age}"') }
or
@pecha7x
pecha7x / person.rb
Last active November 24, 2016 09:47
Some examples of RoR model code and Backbone view
class Person < ActiveRecord::Base
# include module for maintenance person.status
include Person::Status
# soft delete support for model
acts_as_paranoid
# logs all changes for model
audited associated_with: :company
has_associated_audits
@pecha7x
pecha7x / application_controller.rb
Created June 30, 2016 21:57
- process a request based on subdomain 1. locale 2. view, images 3. some model level code calling for only harbin and cannon 4. load subdomain specific css/js file
class ApplicationController < ActionController::Base
around_filter :scope_current_tenant
after_filter :set_locale
layout :tenant_layout
prepend_view_path "app/views/#{current_tenant}"
def current_tenant
@current_tenant ||= Tenant.find_by_subdomain(request.subdomain)
end
#1) What is your favorite Ruby class/library or method and why?
I like Ruby in all. Some awesome points: Blocks/Lambdas, "Everything is an Object", Metaprogramming, etc.
---------------
#2) Given HTML: "<div class="images"><img src="/pic.jpg"></div>" Using Nokogiri how would you select the src attribute from the image? Show me two different ways to do that correctly the the HTML given.
document = Nokogiri::HTML(open("http://lalala.com/"))
document.at_css('.images img').attr('src')
#or
document.xpath('//div[@class="images"]/img/@src').map {|s| s.value }
---------------

IF THIS IS YOUR FIRST TIME HERE READ THIS ENTIRE SECTION BEFORE YOU BEGIN

ABOUT SHOWMOJO

IN ONE SENTENCE Schedule and confirm showings with prospective renters and buyers 24/7 without even answering the phone.

THE LONGER PITCH

@pecha7x
pecha7x / memberships_to_statuses_analyze.rb
Created May 10, 2018 19:43
memberships_to_statuses_analyze.rb
@client = Integrations::Mindbody.new company_id: company.id
person_without_plans = []
person_with_plans_with_nil_status = []
person_with_plans_with_other_status = []
membership_to_statuses = MindbodyMembershipsToStatuses.where(company_id: company.id)
company.people.where.not(mindbody_id: nil).each do |person|
memberships = @client.active_client_memberships(person.mindbody_id)
memberships.each do |membership|
map = membership_to_statuses.where(
MindbodyMembershipsToStatuses[:membership_name].lower.eq(membership[:name].downcase)
sql =
<<-SQL
(select person_id from abc_duplicates
LEFT JOIN people ON abc_duplicates.person_id = people.id
where abc_duplicates.created_at > now()-interval'48 hours'
and people.company_id in (select id from companies where group_id=99))
SQL
results = ActiveRecord::Base.connection.exec_query(sql)
@affected_companies_ids = [4123,288,4120,4082,238,4129,4109,4084,4094,4110,281,4124,230,4111,4081,2460,2485,277,191,229,4115,300,293,2406,4092,4102,4107,4136,284,4106,4132,276,4079,242,4086,273,279,2474,4118,221,455,316,4105,2439,2455,269,2464,2475,2394,2495,4127,3562,2451,306,2461,2501,2466,2452,4121,4078,227,2481,3329,3621,233,2496,2493,2457,2473,2443,2488,4087,2492,234,298,4083,2467,2328,2441,2445,2400,2477,2491,283,4080,4130,2498,4113,4098,307,4096,2482,2801,4103,4099,2456,2472,308,4085,2463,4097,2440,292,237,4088,282,145,2998,4090,4122,2459,4091,4108,4116,2147,4100,4104,2480,2453,3330,286,2483,4119,4089,4117,4077,280,4128,271,4093,274,232,4131,228,2444,4101,2484,272,4114,296,287,2490,4063,235,224,3686,2476,4095,2442,2465,4126,297,226,275,299,2487,2486,289,278,295,2470,239,2479,291,2494,236,2500,222,223,268,4505,305,2489,270,2839,196,231,4248,2471,290,294,379,285,301,318,2497]
overloaded_numbers = [
'+61488844544',
'+61480027122',
'+61480027088',
'+61480027022',
'+61488852555',
'+61480027033'
set :stage, :production
set :rails_env, 'production'
set :branch, 'master'
server '54.206.28.69',
user: 'deploy',
roles: %w(app web db nginx),
foreman_options: { concurrency: 'web=1' },
puma_options: { workers: 8 }