Skip to content

Instantly share code, notes, and snippets.

@serghost
serghost / rails_postgres_test.rb
Created November 30, 2020 14:38
Rails 6+ postgres bug test script (useful for reproducing issues)
if ARGV.empty?
puts "You can specify the local git repository, i.e. `ruby script.rb ~/work/rails.git`"
end
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
#gem 'rails', git: '#{ARGV[0] || 'https://github.com/rails/rails.git'}', tag: 'v6.0.3.4'
gem 'rails', git: '#{ARGV[0] || 'https://github.com/rails/rails.git'}', tag: 'v6.1.0.rc1'
gem 'pg'
@serghost
serghost / SVG_to_custom_fa5_icons_instructions.md
Last active May 19, 2020 10:33
Generate custom fontawesome 5 icons from list of SVG files exported by Illustrator
class String
def is_palindrome?
str = self.gsub(/[^a-zA-Z]/i, '').downcase
str_size = str.size
raise "Incorrect string" if str_size < 2
half_string_1 = str.slice(0...str_size/2)
half_string_2 = str.slice(-(str_size/2)..-1)
@serghost
serghost / las.rb
Last active May 4, 2016 15:02
Look-and-say ruby variant
def next_node(current_node)
array_of_digits = current_node.to_s.split('')
result = []
array_of_digits.chunk { |n| n }.each do |digit, ary|
result << ary.size
result << digit
end
result.join.to_i
@serghost
serghost / rails_admin.ru.yml
Created March 3, 2016 12:24
RU translation for the gem 'rails_admin' (перевод гема rails_admin)
# 02.03.2016 Перевод gem rails_admin ~> 0.8
# Не забудьте добавить переводы названия модели (в т.ч. мн. ч.) и - опционально - атрибутов.
# Некоторые переводы, где нужны склонения, видоизменены, тем не менее, имхо,
# это не повлияло на удобство интерфейса
ru:
admin:
js:
true: 'True'
false: 'False'
@serghost
serghost / gist:1021539
Created June 12, 2011 13:13
wikiheroes
require 'nokogiri'
require 'open-uri'
i = 0
heroes = []
descriptions = []
image_urls = []
puts "Parsing..."
@serghost
serghost / gist:1017175
Created June 9, 2011 16:54
ah parsing
def update_price_ah # "Аптека Холдинг"
ahold = Supplier.find(37, :include => {:partners => :partners_addition})
# Чтобы не делать мильён запросов в БД по ходу обновления, делаем 1 запрос
# до обновления, и нужную нам инфу распихиваем в хэши
known_products = Hash.new
SupplierProduct.all(:select => "id, code, price", :conditions => {:supplier_id => ahold.id}).each do |s_p|
known_products[s_p.code] = {:id => s_p.id, :price => s_p.price}
end
known_vats = Hash.new