Skip to content

Instantly share code, notes, and snippets.

View Nursultan91's full-sized avatar
🎯
Focusing

Nursultan Kuzhagaliyev Nursultan91

🎯
Focusing
  • Almaty, Kazakhstan
View GitHub Profile
@Nursultan91
Nursultan91 / database.yml
Created December 13, 2017 07:37
вот файл
# PostgreSQL. Versions 9.1 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
@Nursultan91
Nursultan91 / db.yml
Created December 14, 2017 08:32
вот
# PostgreSQL. Versions 9.1 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
@Nursultan91
Nursultan91 / 20180110104437_add_attachment_image_to_photos.rb
Created January 10, 2018 11:57
Рельсе чем то не нравится эта миграция. аборт дает все время. что делать с ней?
class AddAttachmentImageToPhotos < ActiveRecord::Migration
def self.up
change_table :photos do |t|
t.attachment :image
end
end
def self.down
remove_attachment :photos, :image
end
@Nursultan91
Nursultan91 / Client.rb
Created January 11, 2018 12:59
Вот модель клиента
class Client < ActiveRecord::Base
belongs_to :user
has_many :call_center_touches
has_many :support_touches
has_many :sales_touches
has_many :client_events
has_many :events, through: :client_events
def self.text_search(query)
self.where("similarity(name, ?) > 0.2 OR similarity(iin, ?) > 0.2 OR similarity(email, ?) > 0.2 OR similarity(phone, ?) > 0.2" , query, query, query, query).order("similarity(name, #{ActiveRecord::Base.connection.quote(query)}) DESC")
@Nursultan91
Nursultan91 / user.rb
Created January 16, 2018 15:03
авторизация через соцсети
def self.find_for_google_oauth2(access_token, signed_in_resourse=nil)
data = access_token.info
user = User.where(:provider => access_token.provider, :uid => access_token.uid).first
if user
return user
else
registered_user = User.where(:email => access_token.email).first
if registered_user
return registered_user
@Nursultan91
Nursultan91 / application_helper.rb
Created January 16, 2018 15:07
Граватар
def avatar_url(user)
gravatar_id = Digest::MD5::hexdigest(user.email).downcase
if user.image
user.image
else
return "https://www.gravatar.com/avatar/#{gravatar_id}.jpg?d=identicon&s=50"
end
end
@Nursultan91
Nursultan91 / routes.rb
Created January 17, 2018 12:59
Пусть в config/routes.rb пропишут так
devise_for :users, :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout', :edit => 'profile'},
:controllers => {:omniauth_callbacks => "omniauth_callbacks", registrations: 'users/registrations'}
@Nursultan91
Nursultan91 / movies.rb
Created February 21, 2018 17:44
Первое задание по квесту
if ARGV.include? "Titanic"
puts "Titanic is a bad movie"
elsif ARGV.include? "Matrix"
puts "Matrix is a good movie"
else
puts "Haven't seen #{ARGV} yet"
end
@Nursultan91
Nursultan91 / moviespro.rb
Created February 21, 2018 17:56
Усложненная версия первого домашнего задания
good_movies = [ 'Matrix', 'GOT', 'Hobbit', 'LOTR', 'Batman' ]
bad_movies = [ 'Titanic', 'Terminator', 'Cloverfield', 'Vikings', 'WD' ]
bad_answer = bad_movies & ARGV
bad_answer.each { |ba| puts "#{ba} is a bad movie"}
good_answer = good_movies & ARGV
good_answer.each { |ga| puts "#{ga} is a good movie"}
@Nursultan91
Nursultan91 / ranking.rb
Last active February 27, 2018 08:26
Второе задание
if ARGV.length != 1
puts "We need exactly one parameter. The name of a file."
exit;
end
filename = ARGV[0]
puts "Going to open '#{filename}'"
fh = open filename