Skip to content

Instantly share code, notes, and snippets.

View makshark's full-sized avatar
😈
retired

Vitalii makshark

😈
retired
  • ArturIn
  • Ukraine
View GitHub Profile
class Language
AVAILABLE_LANGUAGE = ['en', 'ru']
LANGUAGE = {
DEFAULT: 'en',
RU: 'ru',
EN: 'en'
}
def t(key)
translation = Translation.where(key: key).first
module Constant
class User
def self.ZODIAC
if Language.get_language == 'ru'
%w[Овен Лев Стрелец Телец Дева Козерог Близнецы Весы Водолей Рак Скорпион Рыба]
else
%w[Aries Leo Sagittarius Taurus Virgo Capricorn Gemini Libra Aquarius Cancer Scorpio Pisces]
end
end
end
@makshark
makshark / lan
Created February 6, 2015 00:42
descr
class Language
AVAILABLE_LANGUAGE = ['en', 'ru']
LANGUAGE = {
DEFAULT: 'en',
RU: 'ru',
EN: 'en'
}
def t(key)
translation = Translation.where(key: key).first
@makshark
makshark / js
Created September 6, 2015 11:56
<div class="modalbox" id="modalbox">
<div class="close"><p>X</p></div>
<h2 style="text-align: center;">Заказ звонка</h2>
<form id="myform">
<input type="text" class="youname" name="name" placeholder="Ваше имя" onblur="if (this.placeholder=='') this.placeholder='Ваше имя';" onfocus="if (this.placeholder=='Ваше имя') this.placeholder='';">
<input class="youphone" name="phone" placeholder="Ваш телефон" onblur="if (this.placeholder=='') this.placeholder='Ваш телефон';" onfocus="if (this.placeholder=='Ваш телефон') this.placeholder='';">
<input type="email" class="youname" name="email" placeholder="Ваш email" onblur="if (this.placeholder=='') this.placeholder='Ваш email';" onfocus="if (this.placeholder=='Ваш email') this.placeholder='';">
<input type="submit" value="ОТПРАВИТЬ">
</form>
<div id="thankyou"><p>Спасибо, мы перезвоним</p></div>
1. In the previous code, everything is fine. You can order you records by adding order method and send it field (id).
class User < ActiveRecord::Base
scope :find_by_age, ->(age) { where("users.age = #{age}").order(:id) }
end
2.I assume that the developer incorrectly calculates the number of posts. If a user has a large number of posts, we need to add a callbacks to posts model. In this callbacks we will be increment or decrement users field posts_count. And when we will be call search we can increase our perfomance.
3. Write test for
class Message
def mark_as_read
@makshark
makshark / rb
Created October 20, 2015 15:25
def self.set_range(date = 26)
range = Range.new
if Date.today.strftime('%d') < date
start_date = Date.new((Date.today - 1.month).strftime('%Y').to_i,(Date.today - 1.month).strftime('%m').to_i, 26)
end_date = Date.new((Date.today).strftime('%Y').to_i,(Date.today).strftime('%m').to_i, 26)
range = start_date..end_date
else
end
range
puts "Hello, World"
@makshark
makshark / 2-6
Created December 10, 2015 16:07
m = [-1, 3, 64, 3, 2, -3, 42, -78, -19, 30, 23, 11, 21, -90, 1, -1, 7]
a = []
b = []
count = 1
while count < m.length do
if m[count] % 2 == 0
puts m[count]
//Compare incomming array with number
//Return true if combination is available for simple number
function compareValues(arr, number) {
var digits = ("" + number).split("").sort();
arr = arr.map(String).sort();
if (arr.length == digits.length) {
for (var z = 0; z < digits.length; z++) {
if (digits[z] != arr[z]) {
//Not equal
return false;
function deepSearch(arr, element) {
if (typeof arr != 'number') {
for (var i = 0; i < arr.length; i++) {
result = deepSearch(arr[i], element);
if (result) {
return true;
}
}
return false;
} else {