Skip to content

Instantly share code, notes, and snippets.

View paul-ihnatolia's full-sized avatar

Paul paul-ihnatolia

  • Uzhgorod, Ukraine
View GitHub Profile
@paul-ihnatolia
paul-ihnatolia / Mila.sh
Created February 27, 2012 19:24
Mila's programm
#!/bin/bash
masuvElementiv=( Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto )
#створюємо масив елементів
kilkistElementivMasivu=${#masuvElementiv[@]} #отримуємо кількість елементів у масиві
index=0 #ініціалізуємо зміну, за допомогою якої індиксуватимемо масив
while [ "$index" -lt "$kilkistElementivMasivu" ] #поки зміна менша за довжину масиву
<table padding="1">
<tr>
<td> <hr id = "line_2"/></td>
<%@tab.each do |el|%>
<%unless(el[:label]==@choose)%>
<td class="left"><div/></td><td class="navbar"><span class="text"><%= link_to el[:label],el[:url] %></span></td><td class="right"></td>
<%else%>
<td id="left_a"><div/></td><td id="navbar_a"><span id="active"><%= link_to el[:label],el[:url] %></span></td><td id="right_a"></td>
<%end%>
<td></td>
@paul-ihnatolia
paul-ihnatolia / gist:1021760
Created June 12, 2011 16:59
Перевірка строки на паліндром.rb
str = " ABCооооолльоCBA"
p str.gsub(/[^A-Z]/,"") == str.gsub(/[^A-Z]/,"").reverse
p str.scan(/[A-Z]/).join("") == str.scan(/[A-Z]/).join("").reverse
p str.split("").select{|x| x>="A" && x<="Z"}.join("") == str.split("").select{|x| x>="A" && x<="Z"}.join("").reverse
@paul-ihnatolia
paul-ihnatolia / gist:1021627
Created June 12, 2011 14:48
Строки.rb
str = " Дана, строка в которой записаны слова через пробел. Необходимо перемешать в каждом слове все символы в случайном порядке кроме первого и последнего"
p str.delete("[.,!?]").split(" ").each {|x| n = x.split("");n.pop;n.shift;n = n.sort_by{rand};n.push(x.split("").pop);x.split("").size>1?n.unshift(x.split("").shift): n; p n.join("") }
class Obrobka_textu
def initialize (filename = 0)
if filename!=0
file = File.open(filename,'r')
@content_of_file = file.read
file.close()
end
end
def vuvid
puts @content_of_file
@paul-ihnatolia
paul-ihnatolia / custom_timestamps.rb
Created April 23, 2015 13:19
Custom timestamps in rails
# As an option can be placed
# in models/concerns
module CustomTimestamps
extend ActiveSupport::Concern
included do
class_attribute :custom_updated_at, :custom_created_at
before_save :update_custom_updated_at
before_create :set_custom_created_at
end
@paul-ihnatolia
paul-ihnatolia / custom_timestamps.rb
Created April 23, 2015 13:13
Custom timestamps in rails
module CustomTimestamps
extend ActiveSupport::Concern
included do
class_attribute :custom_updated_at, :custom_created_at
before_save :update_custom_updated_at
before_create :set_custom_created_at
end
def update_custom_updated_at